-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fixes virtual value not being used #975
Conversation
hey @GriffinHeart I appreciate what you did here 😄, but Virtual value is used behind the scenes, on every association that doesn't have a serializer itself as you check here I'm not sure if Also, I can't see a use case, because you can only work with static values. But if you use the a method to override it instead, you have access to I'll not close it right now because I may have not seen some use case here, did you had something in mind when you decided to work on it? 😄 Btw your virtual value representation doesn't match the JSON API format. Check the resource linakge and the resource identifier object
|
On the other hand @GriffinHeart has pointed out that - resource[:relationships][name] = { data: nil }
+ resource[:relationships][name] = { data: val } |
Indeed. But |
Fortunately, it appears the only place this code is used is here.
Which means this code is equivalent to the below diff, unless I'm missing something +50 def add_relationship(resource, name, serializer)
-50 def add_relationship(resource, name, serializer, val=nil)
…
137 def add_resource_relationships(attrs, serializer, options = {})
138 if association.respond_to?(:each)
139 add_relationships(attrs, name, association)
140 else
141 if opts[:virtual_value]
+142 add_relationship(attrs, name, nil)
-142 add_relationship(attrs, name, nil, opts[:virtual_value])
143 else
144 add_relationship(attrs, name, association) |
@joaomdmoura Sorry for a late reply. My biggest issue is that if you add relationships that don't have a serialiser using the jsonapi adapter they will be rendered as In either case I just want the option to be able to render something instead of a |
@GriffinHeart you are right! Just tested it. Great catch! So yeah, I'm willing to merge it. But I don't think it should be an option. But this might be done in another PR. Another optmization would be formatting the object to fit with the JSON API conventions as I mentioned earlier, guaranteeing it would have the usual I'm merging this one because it's a great fix! But would be awesome to see both optimizations in further PRs 😄 |
Fixes virtual value not being used
@joaomdmoura Agreed, I think the real use case is not has_many :rewards
def rewards
{ ...somestub }
end and have the adapter use that for serialisation. |
First PR here so let me know if I should change something,
Noticed that
virtual_value
was never being used and this PR fixes it