August 19, 2006

Posted by John

Older: memcached Intro

Newer: UJS Rails Plugin

has_many :through gets more magic

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.

1 Comment

  1. Steven Jones Steven Jones

    Oct 15, 2006

    I’ve seen this reported as a bug before ( I’m glad someone finally fixed it!

Thoughts? Do Tell...

textile enabled, preview above, please be nice
use <pre><code class="ruby"></code></pre> for code blocks


Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.


Release your software more often with fewer problems.
Flip your features.