Ruby on Rails - HABTM relationships

No Gravatar

Using has_and_belongs_to_many is great if you want to manage simple HABTM assoctions, although it provides no access as far as I am aware to other attributes if present in the join table. For a more complex join, you’ve gotta code it by hand.
I came across a bug with HABTM today. Do not add an id field to the join table, if you do, the habtm join table id will be populated to contain the id of your joined model, rather than an auto-incremented number.
This inevitably leads to problems! Check out the habtm reference here for more info.

Tags: ,

Leave a Reply

You must be logged in to post a comment.


nogeek.org is Digg proof thanks to caching by WP Super Cache!