-
Markus Doits authored
Before this was not possible: ```ruby class Zine < ActiveRecord::Base has_many :interests, inverse_of: :zine has_many :humans, through: :interests, source: :interestable, source_type: 'Human' end class Interest < ActiveRecord::Base belongs_to :zine, inverse_of: :interests belongs_to :interestable, polymorphic: true, inverse_of: :interests end class Human < ActiveRecord::Base has_many :interests, as: :interestable, inverse_of: :interestable end zine = Zine.create! zine.humans.create! # => ArgumentError: Polymorphic associations do not support computing the class. ``` Now the code checks whether the association is polymorphic and uses the correct code to get the inverse association.
Markus Doits authoredBefore this was not possible: ```ruby class Zine < ActiveRecord::Base has_many :interests, inverse_of: :zine has_many :humans, through: :interests, source: :interestable, source_type: 'Human' end class Interest < ActiveRecord::Base belongs_to :zine, inverse_of: :interests belongs_to :interestable, polymorphic: true, inverse_of: :interests end class Human < ActiveRecord::Base has_many :interests, as: :interestable, inverse_of: :interestable end zine = Zine.create! zine.humans.create! # => ArgumentError: Polymorphic associations do not support computing the class. ``` Now the code checks whether the association is polymorphic and uses the correct code to get the inverse association.
Loading