ja_serializer v0.18.1 JaSerializer.Relationship.HasOne View Source
Struct representing a HasOne (or belongs to) relationship.
The fields are:
serializer
- A Serializer (often a PhoenixView) implementing the JaSerializer.Serializer behaviour.include
- Should this relationship be included (sideloaded) by default. Overridden byinclude
opt to JaSerializer.format/4data
- A struct representing the data for serialization.identifiers
- Should "resource identifiers be included, options are:when_included
and:always
. Defaults to:always
links
- A keyword list of links,self
andrelated
are most common.name
- Name of the relationship, automatically set.
Used when defining relationships without the DSL using the JaSerializer.relationships/2 callback. For example:
def relationships(article, _conn) do
%{
comments: %HasOne{
serializer: MyApp.CommentView,
include: true,
data: article.comments,
}
}
end
See JaSerializer.DSL.has_many/2 for information on defining different types of relationships.