mercredi 25 novembre 2015

Rails has_many through association with inheritance issue

If we have 3 models => Customer, User and Thing and another model Owner thats inherits from User and we try create a has_many through association like this:

class Customer < ActiveRecord::Base
 has_many :things, :dependent => :destroy
 has_many :owners, through: :things
end

class Thing < ActiveRecord::Base
 belongs_to :customer, foreign_key: "customer_id"
 belongs_to :owner, foreign_key: "owner_id"
end

class Owner < User
 has_many :things, :dependent => :destroy
 has_many :customers, through: :things
end

Why @owner.things doesn't work for us? It gives undefined method "things" error

Aucun commentaire:

Enregistrer un commentaire