Davey
(Davey975)
1
I have a Company and a Photo model. A company can have multiple photos. The relation in my Company model is defined as:
'photos' => array(self::HAS_MANY, 'Photo', 'companyId')
The problem is that i sometimes want to show all photos and sometimes i only want to show 3 of them (as a preview).
I know i can get OR all by (in my view file):
foreach($model->photos AS $photo)
OR only 3 for example, by adding this to my relation:
'photos' => array(self::HAS_MANY, 'Photo', 'companyId',
'limit'=>3
)
But I want both, something like using $model->photos->limit(4). Is this possible?
elvan
(Elvan Hidayat)
2
Yes, something like this is possible,
$model->photos(array('limit' => 4))
Davey
(Davey975)
3
Nice, thanks! Works perfect!
I’ve been looking for this for quite a while!
Thanks for the solution!