Moe Sweet
Moe Sweet

Reputation: 3721

CakePHP: How to filter hasMany

I have Event HABTM Category with categories_events table. I want to display only Event with given category_id. So since I have catId I don't need to go till Category model. I could dynamically bind hasMany association from Event to Cat_Event.

How do I set find() second parameter array to achieve this?

Thanks

Upvotes: 1

Views: 921

Answers (1)

bancer
bancer

Reputation: 7525

Try this way from EventsController:

$this->Event->Category->find('all', array(
    'conditions' => array('Category.id' => $catid)
));

Upvotes: 2

Related Questions