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();.
It will require pagination and sorting facility - the default sort will be ‘added_at DESC’.
I have tried using the ‘with’ option of CDbCriteria but that does not seem to work…