this->set('data', $this->Product->find(array('Logo.company_id'=>1,'Product.id '=>2), null, null, 1));
and see if it works (I am a fan of the array notation for $conditions mainly because I build a lot of them on the fly and it just works better for my brain.)
Another thing you can try if this doesn't give the desired results (don't forget you can set the DEBUG to 2 in order to see how CakePHP is building the queries which can be a big help to help you to see how you might need to format the queries to get what you want.
If the query needs to be down the relationship chain more then you might need to resort to using bind model to change the conditions in the relation as you go. It only lasts for the calling of the action. Below is an examply of one that I do.
$this->TourCategory->bindModel(array('hasAndBelongsToMany' => array('Tour' => array('conditions'=>'Tour.fl_active=1','order'=>'Tour.title ASC'))));
As a side note you can use unbindModel as a way of getting CakePHP to return less data from the DB.
$this->TourCategory->Tour->unbindModel(array('hasMany'=>array('TourContent')));
Sometimes this is more effective (or the only way to return different relations in different situations)
Hope that is a little more helpful. Remember to check the http://manual.cakephp.org and the http://api.cakephp.org for more up to date and fun tidbits. There are also some great things out on the web in some blogs and other resources that are linked to from the cakephp.org homepage.
HTH
Sam D
On 7/12/06, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
Thanks much for the help, but what exactly do you mean (and what syntax
should I use)?
Samuel DeVore wrote:
> try array('Logo.company_id'=>1,'Product.id'=>2)
>
> On 7/12/06, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote:
> >
> >
> > I have a HABTM relationship between Products and Logos. When I use
> > something like this:
> >
> > $this->set('data', $this->Product->find("id = 2", null, null, 1));
> >
> > The result is the following:
> >
> > Array
> > (
> > [Product] => Array
> > (
> > [id] => 2
> > [name] => Chase and Ken T-Shirt
> > [description] => Blandit autet irillam integer ...
> > [price] => 7.95
> > [quantity] =>
> > [active] => 1
> > [featured] => 0
> > [cart] => 1
> > [brand_id] => 0
> > [created] =>
> > [modified] =>
> > )
> >
> > [Logo] => Array
> > (
> > [0] => Array
> > (
> > [id] => 3
> > [name] => Screenprinted Gentex Logo
> > [location] => Back
> > [price] => 0.75
> > [company_id] => 1
> > )
> >
> > [1] => Array
> > (
> > [id] => 4
> > [name] => Screenprinted Serious Cams Logo
> > [location] => Breast
> > [price] => 0.50
> > [company_id] => 2
> > )
> > )
> > )
> >
> > However, when we end up having a bunch of logos, this result will be
> > enormous. How do I have the same result but limit the logos to having a
> > "company_id" of 1. I tried the following:
> >
> > $this->set('data', $this->Product->find("id = 2 AND company_id = 1",
> > null, null, 1));
> > $this->set('data', $this->Product->find("id = 2 AND logo.company_id =
> > 1", null, null, 1));
> >
> > But neither seemed to work; the error says field "company_id" not
> > found. What to do?
> >
> > Thanks in advance!
> >
> >
> > >
> >
>
> ------=_Part_241_20267607.1152747189681
> Content-Type: text/html; charset=ISO-8859-1
> X-Google-AttachSize: 4704
>
> try array(' Logo.company_id'=>1,'<a href="" href="http://Product.id">http://Product.id">Product.id</a>'=>2) <br><br><div><span class="gmail_quote">On 7/12/06, <b class="gmail_sendername"><a href="" [EMAIL PROTECTED]">[EMAIL PROTECTED]</a></b>
> <<a href="" href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED] ">[EMAIL PROTECTED]</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I have a HABTM relationship between Products and Logos. When I use
> <br>something like this:<br><br>$this->set('data', $this->Product->find("id = 2", null, null, 1));<br><br>The result is the following:<br><br>Array<br>(<br> [Product] => Array<br> (<br> [id] => 2
> <br> [name] => Chase and Ken T-Shirt<br> [description] => Blandit autet irillam integer ...<br> [price] => 7.95<br> [quantity] =><br> [active] => 1<br>
> [featured] => 0<br> [cart] => 1<br> [brand_id] => 0<br> [created] =><br> [modified] =><br> )<br><br> [Logo] => Array<br> (<br> [0] => Array
> <br> (<br> [id] => 3<br> [name] => Screenprinted Gentex Logo<br> [location] => Back<br> [price] => 0.75<br> [company_id] => 1
> <br> )<br><br> [1] => Array<br> (<br> [id] => 4<br> [name] => Screenprinted Serious Cams Logo<br> [location] => Breast
> <br> [price] => 0.50<br> [company_id] => 2<br> )<br> )<br>)<br><br>However, when we end up having a bunch of logos, this result will be<br>enormous. How do I have the same result but limit the logos to having a
> <br>"company_id" of 1. I tried the following:<br><br>$this->set('data', $this->Product->find("id = 2 AND company_id = 1",<br>null, null, 1));<br>$this->set('data', $this->Product->find("id = 2 AND
> logo.company_id =<br>1", null, null, 1));<br><br>But neither seemed to work; the error says field "company_id" not<br>found. What to do?<br><br>Thanks in advance!<br><br><br>
> ------=_Part_241_20267607.1152747189681--
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
- How do I limit HABTM results with find function? [EMAIL PROTECTED]
- Re: How do I limit HABTM results with find function... Samuel DeVore
- Re: How do I limit HABTM results with find func... [EMAIL PROTECTED]
- Re: How do I limit HABTM results with find ... Samuel DeVore
