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 byincludeopt to JaSerializer.format/4data- A struct representing the data for serialization.identifiers- Should "resource identifiers be included, options are:when_includedand:always. Defaults to:alwayslinks- A keyword list of links,selfandrelatedare 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,
}
}
endSee JaSerializer.DSL.has_many/2 for information on defining different types of relationships.