Yesterday, Jeremy Kemper checked in a change that allows adding records to has_many :through associations using <<, push and concat. This means that has_and_belongs_to_many can officially go the way of the dodo. Now, you can create this type of relationship as easy as:

post.tags << Tag.find_or_create_by_name("magic")

as opposed to the old way:

post.taggings.create!(:tag => Tag.find_or_create_by_name("magic"))

You can read the full summary of the change and a few more tips to go along with it at Josh Susser’s blog.

Leave a Reply


(textile enabled)