Hi, I have a model called Media that belongsTo Artist and hasMany Vote. I am trying to fetch Vote and Artist data from within the Media model. I am using containable to try and fetch the Artist and Vote data, without fetching another related model. With or without the containable behaviour, the find() call does not fetch Vote data. It happily fetches Artist data, and the other related Model I haven't mentioned. When using containable it doesn't fetch the other Model (so containable is working on some level).
Here is the call to find() from within media.php (the model file).
$votes = $this->find('all',
'fields'=>array('Media.artist_id','COUNT(*) AS votes'),
"Vote.created BETWEEN '" . $start . "' AND '" . $end . "'",
'Artist.department_id' => $department
Media has actAs = array('Containable');, and var $belongsTo = 'Artist';, and var $hasMany = 'Vote';. Vote has var $belongsTo = 'Media';.
The SQL that is generated:
SELECT `Media`.`artist_id`, COUNT(*) AS votes, `Media`.`id` FROM `media` AS `Media` LEFT JOIN `artists` AS `Artist` ON (`Media`.`artist_id` = `Artist`.`id`) WHERE `Vote`.`created` BETWEEN '2010-11-08 00:00:00' AND '2010-11-14 23:59:59' AND `Artist`.`department_id` = 1 GROUP BY `Media`.`artist_id` ORDER BY `votes` DESC
Obviously I get the error "Unknown column 'Vote.created' in 'where clause'".
Can anyone help me out?