I was suggesting in a minimilist, baby on lap sleeping while I'm typing kind of way to try using

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'=&gt;1,'<a href="" href="http://Product.id">http://Product.id">Product.id</a>'=&gt;2)&nbsp; <br><br><div><span class="gmail_quote">On 7/12/06, <b class="gmail_sendername"><a href="" [EMAIL PROTECTED]">[EMAIL PROTECTED]</a></b>
>  &lt;<a href="" href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED] ">[EMAIL PROTECTED]</a>&gt; 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-&gt;set('data', $this-&gt;Product-&gt;find(&quot;id = 2&quot;, null, null, 1));<br><br>The result is the following:<br><br>Array<br>(<br>&nbsp;&nbsp;&nbsp;&nbsp;[Product] =&gt; Array<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[id] =&gt; 2
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[name] =&gt; Chase and Ken T-Shirt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[description] =&gt; Blandit autet irillam integer ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[price] =&gt; 7.95<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[quantity] =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[active] =&gt; 1<br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[featured] =&gt; 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[cart] =&gt; 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[brand_id] =&gt; 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[created] =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[modified] =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;[Logo] =&gt; Array<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<br>&nbsp;&nbsp;&nbsp;&nbs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=&gt; Array<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[id] =&gt; 4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[name] =&gt; Screenprinted Serious Cams Logo<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[location] =&gt; Breast
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[price] =&gt; 0.50<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[company_id] =&gt; 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<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>&quot;company_id&quot; of 1. I tried the following:<br><br>$this-&gt;set('data', $this-&gt;Product-&gt;find(&quot;id = 2 AND company_id = 1&quot;,<br>null, null, 1));<br>$this-&gt;set('data', $this-&gt;Product-&gt;find(&quot;id = 2 AND
> logo.company_id =<br>1&quot;, null, null, 1));<br><br>But neither seemed to work; the error says field &quot;company_id&quot; 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to