Please sign in to comment.
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 <firstname.lastname@example.org> Signed-off-by: Jeremy Kemper <email@example.com>
- Loading branch information...
Showing with 418 additions and 12 deletions.
- +9 −3 activerecord/lib/active_record/associations.rb
- +6 −2 activerecord/lib/active_record/associations/association_collection.rb
- +14 −0 activerecord/lib/active_record/associations/association_proxy.rb
- +11 −1 activerecord/lib/active_record/associations/belongs_to_association.rb
- +5 −0 activerecord/lib/active_record/associations/has_many_association.rb
- +5 −5 activerecord/lib/active_record/associations/has_many_through_association.rb
- +10 −1 activerecord/lib/active_record/associations/has_one_association.rb
- +21 −0 activerecord/lib/active_record/reflection.rb
- +252 −0 activerecord/test/cases/associations/inverse_associations_test.rb
- +7 −0 activerecord/test/fixtures/faces.yml
- +29 −0 activerecord/test/fixtures/interests.yml
- +5 −0 activerecord/test/fixtures/men.yml
- +5 −0 activerecord/test/fixtures/zines.yml
- +5 −0 activerecord/test/models/face.rb
- +4 −0 activerecord/test/models/interest.rb
- +7 −0 activerecord/test/models/man.rb
- +3 −0 activerecord/test/models/zine.rb
- +20 −0 activerecord/test/schema/schema.rb
Oops, something went wrong.