chiya/lib/chiya/notes/note_image.ex
2023-03-09 07:28:06 +01:00

28 lines
635 B
Elixir

defmodule Chiya.Notes.NoteImage do
use Ecto.Schema
use Waffle.Ecto.Schema
import Ecto.Changeset
schema "note_images" do
field :content, :string, default: ""
field :path, Chiya.Uploaders.NoteImage.Type
field :note_id, :id
timestamps()
end
@doc false
def changeset(note_image, attrs) do
note_image
|> cast(attrs, [:content, :note_id])
|> cast_attachments(attrs, [:path], allow_paths: true)
|> validate_required([:path, :note_id])
end
@doc false
def insert_changeset(note_image, attrs) do
note_image
|> cast(attrs, [:note_id])
|> validate_required([:note_id])
end
end