Tuesday, September 16, 2008

Re: Handling your own model associations

If I wanted to polarize it I'd say that Cakes automatic associations
are at their best when you always want the associated data. They are
at their least useful when you have an association that you very
seldom want the associated data and it has a real impact on
performance to query for it needlessly.

Generally I use associations a lot. But I have gone the other way once
or twice.

There is also nothing to stop you from doing the binding/unbinding in
your get_comments() method, or more likely get_with_comments(). You
could possibly decide that your model can be "light" or "heavy" and
then do the appropriate gindings in a function called setHeavy() or
something like that.

There is also the containable and bindable behaviours that both take a
slightly different approach to optimizing associations and recursion.
I have only done a custom query for associated data when the
conditions for the association have been a little complex.


On Sep 16, 6:31 am, DanielMedia <danielmedi...@gmail.com> wrote:
> Hey all,
>
> I'm wondering if anyone out there has chosen to bypass Cake's
> associations and use a more traditional approach. For example, if I
> want to get all the comments in an article, I could write my own
> method and call $this->Article->get_comments(). Seems like an easier
> approach than having to worry about binding/unbinding. I guess what
> I'm really asking here is, what is the downside (if any) of bypass
> Cake's "auto-magic" features like associations. For example, if I want
> fine-grained control over caching of comments via memcache, am I
> losing something by bypassing Cake's conventions? The only thing I can
> think of is that I would have to use custom query pagination. Any
> other thoughts?
--~--~---------~--~----~------------~-------~--~----~
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: