Hmmm... Me thinks you have a logic problem. If "Classification belongsTo Ad " and "Location belongsTo Ad" then searching by both Location.id and Classification.id at the same time is redundant, since they would both share (at most) exactly one parent.
So if "Classification belongsTo Ad ", then Classification has only one parent, and you can simply do this: $this->Ad->Classifications->recursive = 3; $data = $this->Ad->Classifications->findById($this->data['Classification']['id']); $ad = $data['Ad']; Or if "Location belongsTo Ad ", then Location has only one parent, and you can simply do this: $this->Ad->Location->recursive = 3; $data = $this->Ad->Location->findById($this->data['Location']['id']); $ad = $data['Ad']; Back to the logic problem... If one ad can have more than one classification, and many adds can share the same classification, then you are not using the correct relationships. Based on your question, I suspect you should be using hasAndBelongsToMany. If you think this is possible, read the model chapter of the cake manual again: http://manual.cakephp.org/chapter/models Otherwise, ignore my response. sc On Nov 19, 12:18 am, "naryga" <[EMAIL PROTECTED]> wrote: > Ok, I have 3 models: > Ad, Classification, Location > Ad hasMany Classification,Location > Location belongsTo Ad > Classification belongsTo Ad > I want to be able to search for Ads based on the associated > Classifications and Locations. I've tried using something like: > <code> > $this->Ad->findAll("Classification.id = > {$this->data['Classification']['id']} AND Location.id = > {$this->data['Location']['id']}"); > </code> > But this results in: "SQL Error in model Post: 1054: Unknown column > 'Classification.id' in 'where clause'" > Using Debug: 3, I found that the problem seems to be that when > searching on a model with hasMany associations, an SQL alias is not > created for the associated modles (ie, Classification as > classifications). However, changing my where statment to > classifications.id = ... Doesn't seem to help. > > If I only wanted to use one of the associated models to limit the > results, I would use > $this->Ad->Classifications->findAll("Classification.id = > {$this->data['Classification']['id']}); which works just fine. Is > there some other way I should be doing this? Thanks in advance! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" 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 -~----------~----~----~----~------~----~------~--~---
