forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow to autosave associations with polymorphic has many through join…
… model and inverse of 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 wether the association is polymorphic and uses the correct code to get the inverse association.
- Loading branch information
Showing
4 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters