association failing in Rails 3.2 ActiveRecord::InverseOfAssociationNotFoundError -
i've got buildings, apartments, residences , users reason aren't playing together. not sure i'm missing.
class building < activerecord::base attr_accessible ... has_many :apartments, inverse_of: :building ... end class apartments < activerecord::base ... belongs_to :building, inverse_of: :apartment has_many :residences, inverse_of: :apartment ... end class residence < activerecord::base ... belongs_to :apartment, inverse_of: :residence belongs_to :user, inverse_of: :residence ... end class user < activerecord::base ... has_many :residences, inverse_of: :user ... end
in rails console have problems inverse associations:
a.class
=> apartment(id: integer, building_id: integer, ..., created_at: datetime, updated_at: datetime)
a.building
activerecord::inverseofassociationnotfounderror: not find inverse association building (:apartment in building) /users/[me]/.rvm/gems/ruby-1.9.3-p194@r3t2/gems/activerecord-3.2.8/lib/active_record/reflection.rb:246:in `check_validity_of_inverse!'
h.class
=> residence(id: integer, apartment_id: integer, user_id: integer..., created_at: datetime, updated_at: datetime)
h.user
activerecord::inverseofassociationnotfounderror: not find inverse association user (:residence in user) /users/[me]/.rvm/gems/ruby-1.9.3-p194@r3t2/gems/activerecord-3.2.8/lib/active_record/reflection.rb:246:in `check_validity_of_inverse!'
i go on. relationship between these classes seem getting hung on inverse. i've tried various iterations on last couple of hours calling "ma ma!" super grateful leads.
why use :inverse_of? rails determine inverse relationships case :belongs_to , :has_many declarations have names match classes.
Comments
Post a Comment