Thursday, June 10, 2010

Re: Getting additional Tag details with HABTM

On Jun 9, 3:45 pm, Matthew Dunham <m...@umpcmedia.com> wrote:
> Ok my models are as follows:
>
> Product HABTM Tags (with products_tags table)
> Tag belongsTo TagGroup
>
> Can some help me work out the following problem I'm having: How can I
> get all tags for a certain product ID, along with their Tag Group?

If you're not already, use ContainableBehavior. Personally, I include
it in my AppModel as I use it quite a lot. A basic example:

$data = $this->Product->find(
'first',
'conditions' => array(
'Product.id' => $id
),
'fields' => array(...),
'contain' => array(
'Tag' => array(
'TagGroup'
)
)
);

Also, if you want to fetch all products by a particular tag, have a
look at this article by Nate:
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find

I'm not sure how you would incorporate this to get the TagGroup,
though, but I'd guess that could be done.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate