Repository navigation
Conversation
Author
|
I have signed the CLA! |
Contributor
|
Thanks! |
amomchilov
enabled auto-merge
October 29, 2026 14:55
amomchilov
force-pushed
the
type-source-type-through-associations
branch
from
November 5, 2026 20:07
6f3c8ca to
19bf601
Compare
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
A
has_many/has_one :throughassociation whose source is a polymorphicbelongs_tois generated as untyped, even whensource_type:pins the class:Rails resolves the class from
source_type(Client.reflect_on_association(:safe_keepers).klass # => SafeKeeper), so the association can only holdSafeKeeperrecords.polymorphic_association?follows the source reflection, which is polymorphic, and ignoressource_type.#1990 fixed the same symptom by dropping the polymorphic check entirely, and was closed with a CI failure. This change is narrower: only a through reflection with
source_typeis treated as non-polymorphic. A polymorphicbelongs_toand a through association withoutsource_typeare unchanged.Implementation
polymorphic_association?returnsfalsefor a through reflection whose options includesource_type.type_forandrelation_type_forthen usereflection.klass, which Rails computes fromsource_type.Tests
Added a spec, with and without relations enabled, in
spec/tapioca/dsl/compilers/active_record_associations_spec.rb:has_many :throughwithsource_type→::SafeKeeper::PrivateCollectionProxy(::ActiveRecord::Associations::CollectionProxy[::SafeKeeper]without relations);has_one :throughwithsource_type→T.nilable(::SafeKeeper), and typedbuild_/create_/reload_methods.Both fail without the change.