fabrisss
(Fabrisss)
November 7, 2011, 4:42pm
1
Hi,
I don’t understand how to combine relational query with a CDbCriteria in order to get all the related records (‘items’ in the following example) of an instance with some specific conditions.
I wrote something like this but it doesn’t work. Do I need to use ‘scopes’ to achieve this ?
$criteria = new CDbCriteria(array(
'condition' => 'start_date > '.$now,
'order' => 'start_date ASC',
));
$items = $this->items(array(
'criteria'=>$criteria,
));
Thank you,
Fabrice
l.jurgs
(L Jurgs)
November 8, 2011, 12:42pm
2
fabrisss:
Hi,
I don’t understand how to combine relational query with a CDbCriteria in order to get all the related records (‘items’ in the following example) of an instance with some specific conditions.
I wrote something like this but it doesn’t work. Do I need to use ‘scopes’ to achieve this ?
$criteria = new CDbCriteria(array(
'condition' => 'start_date > '.$now,
'order' => 'start_date ASC',
));
$items = $this->items(array(
'criteria'=>$criteria,
));
Thank you,
Fabrice
Edit:
You’re almost there:
$items = $this->items(array('condition' => 'start_date > :now', 'order' => 'start_date ASC', 'params' => array(':now' => $now)));
It just doesn’t take CDbCriteria as a parameter, it takes the same parameters as is specified in a relation.