Thanks for the reply.  Let me expand abit.  Model 'A' hasMany 'B' and
hasMany 'C'.  I want to find the instance of model 'A' that has a spicific
'B' AND a specific 'C'.  Now here's the part I left out.  Model 'D' hasMany
'B' and 'E' hasMany 'C'.  So, a given 'B' or 'C' belongs to only one 'A',
but also to only  one 'D' or 'E' (as apposed to many  'A', 'D' & 'E's).
Basically, 'A' hasAndBelongsTo 'D' and 'E', but the join tables are too
complex for cake's standard habt relationship to work (there's more in there
than I've described).  So I created a model for the join tables and made the
change in the relationships.

So, one 'Ad' can have many 'Classifications', and many 'Locations', but I'm
looking for the specific 'Ad' that has a 'Classification' AND a 'Location'
containing the correct 'Category' and 'City' respectively.

However, the question remains, is it posible to use a feild from a table
associated with a hasMany relationship in the findAll($conditions) array?

What I've recently decided to try on monday is to do:
$var1 = $this->Ad->Location->findAll($conditions);
$var2 = $this->Ad->Classification->findAll($conditions);
$ads = array_intersect($var1, $var2);

Although that seems like a weird way to do it.  Then again, maybe my whole
concept is the weird way to do it in the first place.
--
ng

On 11/19/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> 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!
>
>
> >
>


-- 

Nathan Garza

AshLeaf Media | Director of Technology Innovations
_________________________________________________
www.ashleafmedia.com | [EMAIL PROTECTED] | 832.514.5726


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to