I'm trying to use containable in a paginated query. The code is below, in full.
$this->paginate = array(
'conditions'=>array(
'Track.pending'=>0,
'Track.status'=>1
),
'contain'=>array(
'Vote'=>array(
'conditions'=>array(
'Vote.created >'=>$start,
'Vote.created <='=>$end
),
'fields'=>array(
'Vote.vote_type_id',
'Vote.id',
),
),
'Artist'=>array(
'Image'=>array(
'fields'=>array(
'Image.name'
)
),
'Genre'=>array(
'fields'=>array(
'Genre.name'
)
),
'fields'=>array(
'Artist.name',
'Artist.id',
'Artist.slug',
'Artist.city',
'Artist.genre_id'
)
)
),
'fields'=>array(
'Track.id',
'Track.slug',
'Track.name',
'Track.featured',
'Track.plays',
'Track.vote_score',
'Track.vote_week_score',
'Track.video',
'Track.status',
'Track.created'
),
'order'=>$order
);
The direct associations (Vote and Artist) are picked up, but Image and Genre are not. Here's the SQL that is being generated:
SELECT COUNT(*) AS `count` FROM `tracks` AS `Track` LEFT JOIN `artists` AS `Artist` ON (`Track`.`artist_id` = `Artist`.`id`) WHERE `Track`.`pending` = 0 AND `Track`.`status` = 1
SELECT `Track`.`id`, `Track`.`slug`, `Track`.`name`, `Track`.`featured`, `Track`.`plays`, `Track`.`vote_score`, `Track`.`vote_week_score`, `Track`.`video`, `Track`.`status`, `Track`.`created`, `Artist`.`name`, `Artist`.`id`, `Artist`.`slug`, `Artist`.`city`, `Artist`.`genre_id` FROM `tracks` AS `Track` LEFT JOIN `artists` AS `Artist` ON (`Track`.`artist_id` = `Artist`.`id`) WHERE `Track`.`pending` = 0 AND `Track`.`status` = 1 ORDER BY `Track`.`vote_week_score` DESC LIMIT 20
SELECT `Vote`.`vote_type_id`, `Vote`.`id`, `Vote`.`track_id` FROM `votes` AS `Vote` WHERE `Vote`.`created` > '2011-09-26' AND `Vote`.`created` <= '2011-10-03' AND `Vote`.`track_id` IN (24, 35, 31, 25, 27, 34, 56, 58)
Cake is not picking up the deeper associations. Is this a limitation of Containable + paginate or am I missing something?
Thanks!