hasAndBelongsToMany with additional column in join table?

2008-02-21 Thread mason

I have a question for HABTM experts out there. I've got a pretty
standard many:many relationship through a join table, except that I
have an additional column in the join table which I need access to.
Use this as an example:

Tables:
post (id, text)
tag (id, name)
posts_tags (post_id, tag_id, metadata)

So I've got a normal join between posts and tags, and I can easily
enough get a post and its associated tags. What I want to do, though,
is get a post, iterate its tags, and for each tag get both the tag
name and the metadata for its association with the post.

I could do an additional query to get the posts_tags row based on the
post_id and tag_id, but that's one more query and it shouldn't be
necessary, since of course Cake is already getting the join. Anyone
have a clever way of getting at the metadata from the join table?

Thanks very much.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: hasAndBelongsToMany with additional column in join table?

2008-02-21 Thread Samuel DeVore

You can do it in current versions of 1.2 by using a 'with' attribute
in your models it works for me and I gathered the information I needed
mostly from this thread

http://groups.google.com/group/cake-php/browse_frm/thread/419c4485a99e44eb

Sam D

On Thu, Feb 21, 2008 at 10:40 AM, mason [EMAIL PROTECTED] wrote:

  I have a question for HABTM experts out there. I've got a pretty
  standard many:many relationship through a join table, except that I
  have an additional column in the join table which I need access to.
  Use this as an example:

  Tables:
  post (id, text)
  tag (id, name)
  posts_tags (post_id, tag_id, metadata)

  So I've got a normal join between posts and tags, and I can easily
  enough get a post and its associated tags. What I want to do, though,
  is get a post, iterate its tags, and for each tag get both the tag
  name and the metadata for its association with the post.

  I could do an additional query to get the posts_tags row based on the
  post_id and tag_id, but that's one more query and it shouldn't be
  necessary, since of course Cake is already getting the join. Anyone
  have a clever way of getting at the metadata from the join table?

  Thanks very much.

  




-- 
-- 
(the old fart) the advice is free, the lack of crankiness will cost you

- its a fine line between a real question and an idiot

http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/
http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/
http://blog.samdevore.com/cakephp-pages/i-cant-bake/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---