memEx/lib/memex/contexts/context_note.ex

36 lines
930 B
Elixir
Raw Normal View History

2022-07-25 20:21:36 -04:00
defmodule Memex.Contexts.ContextNote do
2022-11-24 12:44:34 -05:00
@moduledoc """
Represents a mapping of a note to a context
"""
2022-07-25 20:21:36 -04:00
use Ecto.Schema
import Ecto.Changeset
2022-11-24 12:44:34 -05:00
alias Memex.{Contexts.Context, Contexts.ContextNote, Notes.Note}
2022-07-25 20:21:36 -04:00
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "context_notes" do
2022-11-24 12:44:34 -05:00
belongs_to :context, Context
belongs_to :note, Note
2022-07-25 20:21:36 -04:00
timestamps()
end
2022-11-24 12:44:34 -05:00
@type t :: %ContextNote{
context: Context.t() | nil,
context_id: Context.id(),
note: Note.t(),
note_id: Note.id(),
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
@type new_context_note :: %ContextNote{}
2022-07-25 20:21:36 -04:00
@doc false
2022-11-24 12:44:34 -05:00
def create_changeset(%Context{id: context_id}, %Note{id: note_id}) do
%ContextNote{}
|> change(context_id: context_id, note_id: note_id)
|> validate_required([:context_id, :note_id])
2022-07-25 20:21:36 -04:00
end
end