Нужно сделать такой запрос
SELECT goods.*
FROM goods, sections, sections_goods
where
sections_goods.good_id = goods.code
and sections_goods.section_id = sections.id
and sections.id = 278
limit 20;
Сделал по CookBook:
class Good extends AppModel {
public $hasAndBelongsToMany = public $hasAndBelongsToMany = array(
'Section' => array(
'className' => 'Section',
'joinTable' => 'sections_goods',
'foreignKey' => 'good_id',
'associationForeignKey' => 'section_id',
'unique' => true
),
'Group' => array(
'className' => 'Group',
'joinTable' => 'groups_goods',
'foreignKey' => 'good_id',
'associationForeignKey' => 'group_id',
'unique' => true
));
public function getRecomendedSection($section, $good){
$recomended = $this->Good->find('all', array(
'conditions' => array(
'Section.section_id' => $good['currentSection']['id']//id =278
),
'fields' => 'Good.*',
'limit' => 20-count($recomend)
));
}
}
Ошибка: Error: Call to a member function find() on null