Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Changeset [5374fb3cad2970c95aa9d294d006b5804b760754] by Murray Steele

Revision 5374fb3cad2970c95aa9d294d006b5804b760754, committed by Murray Steele · December 21st, 2009 @ 09:13 PM

Providing support for :inverse_of as an option to associations.

You can now add an :inverse_of option to has_one, has_many and belongs_to associations. This is best described with an example:

class Man < ActiveRecord::Base
has_one :face, :inverse_of => :man end

class Face < ActiveRecord::Base
belongs_to :man, :inverse_of => :face end

m = Man.first
f = m.face

Without :inverse_of m and f.man would be different instances of the same object (f.man being pulled from the database again). With these new :inverse_of options m and f.man are the same in memory instance.

Currently :inverse_of supports has_one and has_many (but not the :through variants) associations. It also supplies inverse support for belongs_to associations where the inverse is a has_one and it's not a polymorphic.

Signed-off-by: Murray Steele muz@h-lame.com
Signed-off-by: Michael Koziarski michael@koziarski.com
Signed-off-by: José Valim jose.valim@gmail.com
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net

Conflicts:

activerecord/lib/active_record/associations/belongs_to_association.rb
activerecord/lib/active_record/associations/has_one_association.rb

http://github.com/rails/rails/commit/5374fb3cad2970c95aa9d294d006b5...

22 changed files

  • A activerecord/test/cases/associations/inverse_associations_test.rb
  • A activerecord/test/fixtures/faces.yml
  • A activerecord/test/fixtures/interests.yml
  • A activerecord/test/fixtures/men.yml
  • A activerecord/test/fixtures/zines.yml
  • A activerecord/test/models/face.rb
  • A activerecord/test/models/interest.rb
  • A activerecord/test/models/man.rb
  • A activerecord/test/models/zine.rb
  • M activerecord/CHANGELOG
  • M activerecord/lib/active_record/association_preload.rb
  • M activerecord/lib/active_record/associations.rb
  • M activerecord/lib/active_record/associations/association_collection.rb
  • M activerecord/lib/active_record/associations/association_proxy.rb
  • M activerecord/lib/active_record/associations/belongs_to_association.rb
  • M activerecord/lib/active_record/associations/has_many_association.rb
  • M activerecord/lib/active_record/associations/has_many_through_association.rb
  • M activerecord/lib/active_record/associations/has_one_association.rb
  • M activerecord/lib/active_record/reflection.rb
  • M activerecord/test/cases/nested_attributes_test.rb
  • M activerecord/test/cases/validations_test.rb
  • M activerecord/test/schema/schema.rb