Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the feedzy-rss-feeds domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data01/virt126885/domeenid/www.saksadogi.com/codegurus.eu/wp-includes/functions.php on line 6121
Using IF condition in SELECT in Active Record SQL scope (for Yii) - CodeGurus

Using IF condition in SELECT in Active Record SQL scope (for Yii)

Instead of a string value use an array to specify different ‘select’ expressions (just a string will get exploded using comma as delimter and there’ll be an error). NB! New variables defined only in SQL query code (with AS) should be defined also in the Model:

// AR variables defined in SQL query code
public $begins_same_day;
public $is_long;

public function scopes()
{
	return array(
		'more' => array(
			'select' => array(
				'*',
				'FALSE AS begins_same_day',
				'IF (DATE(date_to) > DATE(date_from + INTERVAL 1 DAY), TRUE, FALSE) AS is_long'
			),
			'condition' => 'TO_DAYS(date(date_from)) > (TO_DAYS(date(NOW())) + 2)',
			'order' => 'date_from ASC, date_to ASC',
			'limit' => 20
		)
	);
}

Posted

in

, ,

by

Comments

Leave a Reply