I am trying to use relations as part of the criteria to create a CActiveDataProvider. I have the following:
User model:
return array(
'favourites'=>array(self::HAS_MANY, 'UserFavourite', 'user_id', 'order'=>'added_at DESC'),
);
UserFavourite model:
return array(
'user'=>array(self::BELONGS_TO, 'User', 'user_id'),
'listing'=>array(self::BELONGS_TO, 'Listing', 'listing_id'),
);
Controller (view favourites action):
$user = $this->loadUser(Yii::app()->user->id);
How do I create a CActiveDataProvider in my User model that fetches all favourites by the current user - along with the related listing model data for each favourite? So I want to do something like $favourites = $user->getFavourites();.
The CActiveDataProvider should return an array of Listing objects. It should support pagination and sorting - the default sort will be added_at DESC.
I have tried using the with option of CDbCriteria but that does not seem to work...