I wish I would have seen this before I started working with rails’ has_many_and_belongs_to_many relationship stuff. When creating the relationship table (ie. posts_person), make sure that it DOES NOT HAVE AND ID! This is very strange, but it will mess up saving multiple objects.

To fix this, in your migrations, when creating the table (create_table()), make sure you pass in the :id=>false option to not have rails automatically create the id field.

Suprisingly, this is actually documented in the api, http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html under the habtm description.

I wish I would get some type of warning that this is going on, but oh well…

Be Sociable, Share!