-
Notifications
You must be signed in to change notification settings - Fork 127
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
Remove polymorphic check when generating associating methods #1990
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,7 +287,7 @@ def populate_collection_assoc_getter_setter(klass, association_name, reflection) | |
def type_for(reflection) | ||
validate_reflection!(reflection) | ||
|
||
return "T.untyped" if !constant.table_exists? || polymorphic_association?(reflection) | ||
return "T.untyped" if !constant.table_exists? | ||
|
||
T.must(qualified_name_of(reflection.klass)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I'm getting a failure when running against our core monolith:
Where class OurModel < ApplicationRecord
belongs_to :reference, polymorphic: true
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, this is super useful, I can work on this |
||
end | ||
|
@@ -383,33 +383,13 @@ def relation_type_for(reflection) | |
validate_reflection!(reflection) | ||
|
||
relations_enabled = compiler_enabled?("ActiveRecordRelations") | ||
polymorphic_association = !constant.table_exists? || polymorphic_association?(reflection) | ||
|
||
if relations_enabled | ||
if polymorphic_association | ||
"ActiveRecord::Associations::CollectionProxy" | ||
else | ||
"#{qualified_name_of(reflection.klass)}::#{AssociationsCollectionProxyClassName}" | ||
end | ||
elsif polymorphic_association | ||
"ActiveRecord::Associations::CollectionProxy[T.untyped]" | ||
"#{qualified_name_of(reflection.klass)}::#{AssociationsCollectionProxyClassName}" | ||
else | ||
"::ActiveRecord::Associations::CollectionProxy[#{qualified_name_of(reflection.klass)}]" | ||
end | ||
end | ||
|
||
sig do | ||
params( | ||
reflection: ReflectionType, | ||
).returns(T::Boolean) | ||
end | ||
def polymorphic_association?(reflection) | ||
if reflection.through_reflection? | ||
polymorphic_association?(reflection.source_reflection) | ||
else | ||
!!reflection.polymorphic? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fix: