ja_serializer v0.18.1 JaSerializer.Relationship.HasMany View Source

Struct to represent a HasMany 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 by include opt to JaSerializer.format/4
  • data - A list of structs representing the data.
  • identifiers - Should "resource identifiers be included, options are :when_included and :always. Defaults to :when_included
  • links - A keyword list of links, self and related 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: %HasMany{
      serializer:  MyApp.CommentView,
      include:     true,
      data:        article.comments,
    }
  }
end

See JaSerializer.DSL.has_many/2 for information on defining different types of relationships.