Open
Conversation
bf4
reviewed
Jun 8, 2022
Collaborator
bf4
left a comment
There was a problem hiding this comment.
I think this is what @JamesGlover was referring to
| pluck_fields << Arel.sql("#{concat_table_field(linkage_table_alias, primary_key)} AS \"#{linkage_table_alias}_#{primary_key}\"") | ||
|
|
||
| if linkage_relationship.sti? | ||
| pluck_fields << Arel.sql("#{concat_table_field(linkage_table_alias, 'type')} AS \"#{linkage_table_alias}_type\"") |
Collaborator
There was a problem hiding this comment.
Suggested change
| pluck_fields << Arel.sql("#{concat_table_field(linkage_table_alias, 'type')} AS \"#{linkage_table_alias}_type\"") | |
| pluck_fields << Arel.sql("#{concat_table_field(linkage_table_alias, klass.inheritance_column)} AS \"#{linkage_table_alias}_type\"") |
right?
Contributor
There was a problem hiding this comment.
I think at this point klass is the resource, not the ActiveRecord::Base class, so you'd also need to define an inheritance_column method on JSONAPI::BasicResource.
Although in practice you'd probably want to use _inheritance_column instead, to be consistent with _primary_key.
# lib/jsonapi/basic_resource.rb
def inheritance_column(key)
@_inheritance_column = key.to_sym
end
def _inheritance_column
@_inheritance_column ||= _default_inheritance_column
end
def _default_inheritance_column
@_default_inheritance_column ||=_model_class.respond_to?(:inheritance_column) ? _model_class.inheritance_column : :type
end| ] | ||
|
|
||
| if relationship.sti? | ||
| pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, 'type')} AS #{resource_table_alias}_type") |
Collaborator
There was a problem hiding this comment.
Suggested change
| pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, 'type')} AS #{resource_table_alias}_type") | |
| pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, klass.inheritance_column)} AS #{resource_table_alias}_type") |
right?
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.
This fixes a few issues I found with STI
All Submissions:
New Feature Submissions:
Bug fixes and Changes to Core Features:
Test Plan:
Reviewer Checklist: