-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically guess the inverse associations for STI #23425
Automatically guess the inverse associations for STI #23425
Conversation
(@rails-bot has picked a reviewer for you, use r? to override) |
655dd88
to
d3f77f0
Compare
at a first pass this looks correct. |
d3f77f0
to
ee404fd
Compare
It'd be awesome to get this merged sometime soon. This is the exact behavior I would've expected when interacting with a child record. Instead, for a setup like this: class Challenge < ApplicationRecord
has_many :questions
end
class Question < ApplicationRecord
belongs_to :challenge
end
class MultipleChoiceQuestion < Question
# where `type` == "MultipleChoiceQuestion"
end the following challenge = Challenge.new
MultipleChoiceQuestion.create(challenge: challange) would give me: It seems to know that it's an association, but not really... |
@yui-knk This looks fine to me. Can you rebase? |
ee404fd
to
67ffba0
Compare
@sgrif Rebased! |
a86bd1f
to
d99ba10
Compare
d99ba10
to
11c9be2
Compare
887c51d
to
2730095
Compare
ActiveRecord associations automatically guess the inverse associations. But this feature does not work correctly on assoctions for STI. For example, before this commit ``` class Post < ActiveRecord::Base belongs_to :author end class SpecialPost < Post; end class Author < ActiveRecord::Base has_many :posts has_many :special_posts end ``` `author.posts.first.author` works correctly, but `author.special_posts.first.author` does not work correctly.
2730095
to
30ef715
Compare
ActiveRecord associations automatically guess the inverse associations.
But this feature does not work correctly on assoctions for STI.
For example, before this commit
author.posts.first.author
works correctly, butauthor.special_posts.first.author
does not work correctly.