View Source OnePiece.Commanded.Entity (OnePiece.Commanded v0.19.1)

Defines "Entity" modules.

Summary

Types

The identity key of the entity.

The identity of an entity.

t()

A struct that represents an entity.

Functions

Converts the module into an t/0.

Types

@type identifier_opt() ::
  atom()
  | {key_name :: atom(), type :: atom()}
  | {key_name :: atom(), type :: module()}

The identity key of the entity.

If it's a tuple, the type must be a module that implements the OnePiece.Commanded.ValueObject module or Ecto built-in types

@type identity() :: any()

The identity of an entity.

@type t() :: struct()

A struct that represents an entity.

Functions

Link to this macro

__using__(opts \\ [])

View Source (macro)
@spec __using__(opts :: [{:identifier, identifier_opt()}]) :: any()

Converts the module into an t/0.

Using

Usage

defmodule MyEntity do
  use OnePiece.Commanded.Entity, identifier: :id

  embedded_schema do
    # ...
  end
end

You can also define a custom type as the identifier:

defmodule IdentityRoleId do
  use OnePiece.Commanded.ValueObject

  embedded_schema do
    field :identity_id, :string
    field :role_id, :string
  end
end

defmodule IdentityRole do
  use OnePiece.Commanded.Entity,
    identifier: {:id, IdentityRoleId}

  embedded_schema do
    # ...
  end
end