Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 5/28/2010: rails new :inverse_of association option automatically creates backreferences

Interesting Things

  • has_many and belongs_to associations can now automatically create back references each other, thanks to a Backport of :inverse_of from Rails 3 to rails 2.3.6. This allows us to keep our object graphs more correct and avoid situations where we have 2 copies of the same object because the object graph is walked in reverse. Here’s how to use it:
class Parent < ActiveRecord::Base
  has_one :child, :inverse_of => :parent
  accepts_nested_attributes_for :child

class Child < ActiveRecord::Base
  belongs_to :parent
  validates_presence_of :parent

  1. funny_falcon says:

    I wrote simple “identity map” capable to do job of :inverse_of. Also, it helps to save memory by updating attributes of already fetched objects, instead of creating new instances.

    gem is ar-simple-idmap repository:

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *