debianize-mobilizon/lib/mobilizon/media/picture.ex

33 lines
642 B
Elixir
Raw Normal View History

defmodule Mobilizon.Media.Picture do
@moduledoc """
2019-09-07 02:36:37 +02:00
Represents a picture entity.
"""
2019-09-07 02:36:37 +02:00
use Ecto.Schema
2019-09-07 02:36:37 +02:00
import Ecto.Changeset, only: [cast: 3, cast_embed: 2]
2019-05-31 17:58:03 +02:00
alias Mobilizon.Actors.Actor
2019-09-07 02:36:37 +02:00
alias Mobilizon.Media.File
@type t :: %__MODULE__{
file: File.t(),
actor: Actor.t()
}
schema "pictures" do
embeds_one(:file, File, on_replace: :update)
2019-05-31 17:58:03 +02:00
belongs_to(:actor, Actor)
timestamps()
end
@doc false
2019-09-07 02:36:37 +02:00
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
def changeset(picture, attrs) do
picture
2019-05-31 17:58:03 +02:00
|> cast(attrs, [:actor_id])
|> cast_embed(:file)
end
end