Tuesday, August 4, 2009

Re: Containable - Deep Associations - Sort resulting array

Yeah, the only solutions are either to write a custom query, or use
either 'ad hoc joins' as someone else mentioned, or on-the-fly binding
and unbinding. I would love to see multiple JOIN clauses for these
complex find operations, rather than multiple queries. We'd get less
overhead and a more streamlined return process.

Even the "ad-hoc joins" by Nate (
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find
), while a pretty good solution, go against the 'spirit' of CakePHP I
think. We've already defined the HATBM relationships in the models, so
we shouldn't need to define them again when executing a query.


On Aug 4, 9:33 am, pomares <k...@gordonpomarescentre.com> wrote:
> Here is the custom query I ended up writing quickly. Makes for a very
> lean array too. :-)
>
> SELECT
>   Client.id,
>   Client.firstname,
>   Client.lastname,
>   AdvancementCategory.name,
>   AdvancementCategory.id
> FROM
>   clients as Client,
>   families as Family,
>   advancements as Advancement,
>   advancement_categories as AdvancementCategory
> WHERE
>   Client.family_id = Family.id
>   AND
>   Family.advancement_id = Advancement.id
>   AND
>   Advancement.advancement_category_id = AdvancementCategory.id
>   ORDER BY
>   AdvancementCategory.id,
>   Client.firstname
--~--~---------~--~----~------------~-------~--~----~
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: