Monday, September 29, 2008

Re: Containable Behaviour

I don't think containable will do this for you. Supplying additional
conditions to containments only further restricts the associations of
the initial find. Currently your code is doing the following

find all DealerAddresses in region 64. For each DealerAddress you
found only return the related DealerBranchAddress' if its region is
64.

Containable will only limit the related models found on the initial
find. Not perform additional reverse lookups.
hope that helps.

-Mark

On Sep 29, 10:51 am, gmwebs <gmw...@googlemail.com> wrote:
> I am trying out the Containable behaviour but am not getting the
> correct result (or at least my expected result!).
>
> I have a DealerAddress model (for their head office) which is
> associated to a DealerBranchAddress model (for their branch address)
> and I want to be able to return all dealers in a specific region. This
> needs to be whether their head office or their branch office is in
> that region.
>
> So I have tried the following:
>
> $this->DealerAddress->find('all',
> array('conditions'=>array('DealerAddress.region_id'=>64), 'contain' =>
> array('DealerBranchAddress'=>array('conditions'=>array('DealerBranchAddress.region_id'=>64))))));
>
> That doesn't return the correct result as it seems to be appending an
> AND clause to the query
> which I can see in the debug output as "SELECT blah.... WHERE
> `DealerBranchAddress`.`region_id` = 64 AND
> `DealerBranchAddress`.`dealer_id` = (3)".
>
> I want it to be (pseudo code): find all DealerAddress and
> DealerBranchAddress where region_id=64
>
> Which should return all my dealer addresses, whether it's their head
> or branch office, in region 64.
>
> Any help would be good thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: