I have to ask... if you have to take extra measures to specify your join conditions, why not just provide a method in a model that uses query() with a simple-to-understand SQL statement? All these find() contortions, while interesting, may not be the easiest to maintain later on when you have to decipher what you were trying to do. I suppose you have to worry about SQL statement portability, but really how often do you have to move your database from one server type to another? And if you keep all your queries in your models at least it's easy to find what needs to change should you move to a different database.
On Dec 19, 12:51 pm, Webweave <[email protected]> wrote: > OK, it depends on what you are really trying to fetch. Are you trying > to restrict the Advert results to just those that have data in the > hasMany tables, or are you trying to restrict the child table values ? > > If it's the former, I would just use a condition that includes a > select for that condition specifically. For instance, in my > VolunteerCake application, I have a structure where I have a Job that > has signup Slots associated with it. I want to list jobs with > available slots (meaning there are not more Slot rows than a max field > in the jobs table), so I use a condition like: > > $whereArray = array( > 'AND' => array( > 'Slot.max_signups > (select count(1) > from user_slots s2 where s2.slot_id = Slot.slot_id)', > 'Slot.job_id = '.$id > ) > ); > > Note that the "select count" is enclosed in parens, and compared to > the Slot.max_signups. This correlated sub-query causes the database to > do an implicit join, without Cake having to understand the > relationship. > > If it's the latter, you can add your condition to the belongsTo or do > a separate find for the related data. > > On Dec 19, 1:53 am, dev <[email protected]> wrote: > > > i posted code here:http://bin.cakephp.org/saved/40741 > > > How to join Image and Option tables if i want to set these find > > conditions in Advert? > > > I tried Containable (test2 function), but it selects all Adverts, and > > if i set conditions in first paginate array - it generates the same > > error, bicause tables don't join. > > > How to solve this problem? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
