-
Notifications
You must be signed in to change notification settings - Fork 425
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
Serialize only last record of a has_many association (as if it was a has_one association) #440
Comments
@YassineDM - I have a very similar use case - did you come up with a workaround or otherwise solve this? |
Nevermind. I got this to work the way that I wanted. My structure is this:
The output matches your expected result above. |
@hicklin-james, shouldn't we be able to do this without options[:params] in the controller? |
Yes - you can put whatever you want in |
Thx @hicklin-james, I left it as a side note but will come back to it and let you know... |
I have a user with many heights (stature measurements) recorded in a Height model but would like to serialize only last height (as if it was a has_many association).
I tried to create a (fake) custom has_one association but it does not give me what I was looking for...
app/serializers/user_serializer.rb
app/controllers/users_controller.rb
As is, I get the error:
"heights is not specified as a relationship on UserSerializer."
If I uncomment
# has_many :heights
, I get though:But I don't want to include in the compound document all recorded heights...
Expected result
The text was updated successfully, but these errors were encountered: