Automatically guess the inverse associations for STI #23425
ActiveRecord associations automatically guess the inverse associations.
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
challenge = Challenge.new MultipleChoiceQuestion.create(challenge: challange)
would give me:
It seems to know that it's an association, but not really...
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.