Wednesday, November 30, 2011

Re: Conditions in model associations

you could probably wright a behavior which could "correct" the issue
at runtime
until it is fixed in the not so near future :)


On 30 Nov., 06:59, Jeremy Burns | Class Outfit
<jeremybu...@classoutfit.com> wrote:
> Thanks - this is exactly the issue I am facing. I agree with you; this sort of renders the conditional associations almost useless and I bet it catches a lot of people out. It took me an hour or so to realise what was happening.
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com
>
> On 29 Nov 2011, at 21:25, euromark wrote:
>
>
>
>
>
>
>
> > and I think this is the ticket:
> >http://cakephp.lighthouseapp.com/projects/42648/tickets/1793-model-co...
>
> > On 29 Nov., 22:22, euromark <dereurom...@googlemail.com> wrote:
> >> If I remember right a core member once wrote that this is a known
> >> limitation of the current "conditions array" for relations.
> >> Personally, I think this should be addressed in 2.1 as a bugfix to be
> >> fixed (if I add a global condition it should always be applied, no
> >> matter what).
>
> >> As of right now you probably need to manually join the conditions.
>
> >> On 29 Nov., 18:16, Jeremy Burns <jeremybu...@classoutfit.com> wrote:
>
> >>> I've noticed that if I have conditions on model associations, for
> >>> example:
>
> >>> $hasMany = array(
> >>>         'ActiveUser' => array(
> >>>                 'className' => 'User',
> >>>                 'foreignKey' => 'group_id',
> >>>                 'conditions' => array(
> >>>                         'ActiveUser.active' => 1
> >>>                 )
> >>>         )
> >>> );
>
> >>> ...and bring that key into a find BUT with an added condition, for
> >>> example;
>
> >>> $groups = $this->find(
> >>>         'all',
> >>>         array(
> >>>                 'contain' => array(
> >>>                         'ActiveUser' => array(
> >>>                                 'conditions' => array(
> >>>                                         'ActiveUser.id' => 10
> >>>                                 )
> >>>                         )
> >>>                 )
> >>>         )
> >>> );
>
> >>> ...the condition on the join is ignored. So in this example the user
> >>> with an id of 10 will come back whether he is active or not.
>
> >>> How do I overcome that?
>
> > --
> > Our newest site for the community: CakePHP Video Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: