This project is archived and is in readonly mode.
Changeset [ccea98389abbf150b886c9f964b1def47f00f237] by Murray Steele
May 4th, 2009 @ 11:27 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: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
Committed by Murray Steele
- 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/associations/inverse_associations_test.rb
- M activerecord/test/fixtures/faces.yml
- M activerecord/test/fixtures/interests.yml
- M activerecord/test/fixtures/men.yml
- M activerecord/test/fixtures/zines.yml
- M activerecord/test/models/face.rb
- M activerecord/test/models/interest.rb
- M activerecord/test/models/man.rb
- M activerecord/test/models/zine.rb
- M activerecord/test/schema/schema.rb
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>