tags:

views:

20

answers:

2

Hi,

I have Venues HasMany Events association. In the side bar, I want to list only Venues with at least one event associated. What's the find condition?

+1  A: 

Cut & Paste from the manual ( http://book.cakephp.org/view/74/Complex-Find-Conditions ):

array('fields'=>array('DISTINCT (User.name) AS my_column_name'), 'order'=>array('User.id DESC'));

You could do this from the events end to find active venues.

Leo
A: 

Or you could use counterCache to automatically track the number of events for each venue. Then just use Containable and make sure the conditions on the Venue checks for event_count > 0 in the find call.

http://book.cakephp.org/view/75/Saving-Your-Data

Abba Bryant