mobilizon.chapril.org-mobil.../lib/mobilizon/media/picture.ex
2019-09-07 02:36:37 +02:00

33 lines
642 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 | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
def changeset(picture, attrs) do
picture
|> cast(attrs, [:actor_id])
|> cast_embed(:file)
end
end