This project is archived and is in readonly mode.

#3513 ✓resolved
George Ogata

:inverse_of not honored when replacing a has_one association

Reported by George Ogata | November 26th, 2009 @ 05:12 AM | in 2.3.6

When assigning to, or calling #replace, on a has_one association, the inverse association is not set.

The patch attached fixes this.

require 'active_record'

ActiveRecord::Base.establish_connection('adapter' => "sqlite3", 'database' => ":memory:")
ActiveRecord::Schema.define do
  create_table :parents do
  create_table :children do |t|
    t.integer :parent_id

class Parent < ActiveRecord::Base
  has_one :child, :as => :parent, :inverse_of => :parent

class Child < ActiveRecord::Base
  belongs_to :parent, :inverse_of => :child

parent = =>
new_child =
parent.child = new_child

p  # should be true

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by