apply_filter and apply_sort respects :delegate option of attribute#975
Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom May 5, 2017
Conversation
Contributor
Author
|
maybe we should also change keys in |
Contributor
Author
|
@lgebhardt, @dgeb, @barelyknown, what do you think about this? |
Contributor
|
The fact that the two code changes are exactly the same shows that there needs to be a better solution to mapping resource attributes to model attributes and vice versa. Like @senid231 mentions, a proper solution should probably also take care of validation messages (and the corresponding pointers). Something on a class level like class ProductResource < JSONAPI::Resource
attribute :name, delegate: :title
attribute :price
def self.model_attribute_name(resource_attribute)
# :name => :title | :price => :price
end
def self.resource_attribute_name(model_attribute)
# :title => :name | :price => :price
end
end |
6e773fd to
49f0aee
Compare
Contributor
Author
|
rebased and dried |
Contributor
|
@senid231 Thanks! |
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.
Allows to sort and filter by delegated attribute without additional patching.
For example request like
for such resource
will responds successfully with correct data.