mobilizon.chapril.org-mobil.../lib/mobilizon/media/picture.ex
2019-09-13 02:15:04 +02:00

33 lines
637 B
Elixir

defmodule Mobilizon.Media.Picture do
@moduledoc """
Represents a picture entity.
"""
use Ecto.Schema
import Ecto.Changeset, only: [cast: 3, cast_embed: 2]
alias Mobilizon.Actors.Actor
alias Mobilizon.Media.File
@type t :: %__MODULE__{
file: File.t(),
actor: Actor.t()
}
schema "pictures" do
embeds_one(:file, File, on_replace: :update)
belongs_to(:actor, Actor)
timestamps()
end
@doc false
@spec changeset(t, map) :: Ecto.Changeset.t()
def changeset(%__MODULE__{} = picture, attrs) do
picture
|> cast(attrs, [:actor_id])
|> cast_embed(:file)
end
end