Wednesday, November 25, 2009

Re: Associate by condition

Actually I don't really want to find by the type. I want to have them
all, but that cake internally will only apply that association if the
Model accomplishes the condition.
The point of this behaviour is for performance, because I know
beforehand that some of the retrieved Models will have the association
empty. So I just want a way that I can say, hei! not even try to
retrieve the data for these models, because you won't find anything,
just return the Association data array empty :)

On Nov 24, 9:43 pm, Ian R <ianrick...@gmail.com> wrote:
> Couldn't you just create a method in your model which does this, using
> Find()?  For example, FindStandard() or FindByType('STANDARD')?  I
> believe that's Cake-y, and it keeps your controller lean and your
> model fat :)
>
> Ian
>
> On Nov 24, 2:18 pm, villosil <villo...@gmail.com> wrote:
>
> > Hi,
>
> > Is there any "Cake-way" to fetch data from associations by a previous
> > condition on the main Model? I'll explain myself:
>
> > Let's say I have a Product Model, which has a hasMany association with
> > an Image Model. The Product has a field called type which defines the
> > type of the Product. For example, by the nature of the app, I know
> > that only Products that are Product.type='STANDARD' can have images.
> > But when i make a find('all) cake always try to fetch the Images for
> > every Product.
>
> > For performance, it would be better to define, before the find('all'),
> > to only apply the association on Products which their type was
> > 'STANDARD'.
>
> > Internally on a find('all') over an object A, if a hasMany association
> > exists with a B Object, cake first gets the data of every A object,
> > and then gets for every A object found, the associated B Objects. I
> > mean that for what I'm looking for, that information would be there
> > before trying to fetch the associated data.
>
> > Has someone faced something similar?
>
> > Thanks in advance.
>
> > Vicent,

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: