pass array of unique movies to serializer - #378
Conversation
| } | ||
| options[:include] = [:actors, :'actors.agency', :'actors.agency.state'] | ||
| MovieSerializer.new([movie, movie], options).serialized_json | ||
| MovieSerializer.new(movies, options).serialized_json |
There was a problem hiding this comment.
The problem I see with this change in the documentation is that the variable movies is never declared (as far as I could tell) within the documentation. More of a nitpick than a usage issue.
There was a problem hiding this comment.
right.
I'm thinking about adding the below to Sample Object document
movies = 2.times.map do |i|
m = Movie.new
m.id = i + 1
m.name = 'test movie'
m.actor_ids = [1, 2, 3]
m.owner_id = 3
m.movie_type_id = 1
m
end
and replace [movie, movie] statement in the documentation to declared movies .
How do you think about the above change?
There was a problem hiding this comment.
I wouldn't think you would want the title of both movies to be test movie. Other than that, seems appropriate.
| options[:links] = { self: 'self' } | ||
| options[:include] = [:actors] | ||
| serializable_hash = MovieSerializer.new([movie, movie], options).serializable_hash | ||
| movies = build_movies(2) |
There was a problem hiding this comment.
What do you think about making this a let so you only have to declare it once?
There was a problem hiding this comment.
thanks. I'll replace redundant code by using let statement.
According to JSON API document,
idshould be unique.https://jsonapi.org/format/#document-resource-objects
idof movie generated bylet(:movie)is always same.https://github.com/Netflix/fast_jsonapi/blob/master/spec/shared/contexts/movie_context.rb#L438
So I replace array passed to serializer
[movies, movies]tobuild_movies(2)before:
after: