JsonView.render_relationships
You're seeing just the function
render_relationships
, go back to JsonView module for more information.
Render relationship field for struct. relationships
is a list of {field, view} for mapping render.
For each field, call function View.render()
to render json for relation object.
Example relationships:
relationships = [comments: CommentView, author: UserView]
# or use a custom template instead of default template "user.json" in this case
relationships = [comments: CommentView, author: {UserView, "basic_info.json}]
Result of render_relationships(post, relationships)
equal to output of below code
%{
comments: CommentView.render_many(comments, CommentView, "comment.json"),
author: UserView.render_one(author, UserView, "user.json")
}