Skip to content
  • Murray Steele's avatar
    5374fb3c
    Providing support for :inverse_of as an option to associations. · 5374fb3c
    Murray Steele authored
    
    
    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: default avatarMurray Steele <muz@h-lame.com>
    Signed-off-by: default avatarMichael Koziarski <michael@koziarski.com>
    Signed-off-by: default avatarJosé Valim <jose.valim@gmail.com>
    Signed-off-by: default avatarJeremy Kemper <jeremy@bitsweat.net>
    
    Conflicts:
    
    	activerecord/lib/active_record/associations/belongs_to_association.rb
    	activerecord/lib/active_record/associations/has_one_association.rb
    5374fb3c
    Providing support for :inverse_of as an option to associations.
    Murray Steele authored
    
    
    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: default avatarMurray Steele <muz@h-lame.com>
    Signed-off-by: default avatarMichael Koziarski <michael@koziarski.com>
    Signed-off-by: default avatarJosé Valim <jose.valim@gmail.com>
    Signed-off-by: default avatarJeremy Kemper <jeremy@bitsweat.net>
    
    Conflicts:
    
    	activerecord/lib/active_record/associations/belongs_to_association.rb
    	activerecord/lib/active_record/associations/has_one_association.rb
Loading