26 lines
787 B
Elixir
26 lines
787 B
Elixir
defmodule BDS.Posts.Link do
|
|
@moduledoc false
|
|
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
@primary_key {:id, :string, autogenerate: false}
|
|
@foreign_key_type :string
|
|
|
|
schema "post_links" do
|
|
belongs_to :source_post, BDS.Posts.Post, foreign_key: :source_post_id, references: :id, type: :string
|
|
belongs_to :target_post, BDS.Posts.Post, foreign_key: :target_post_id, references: :id, type: :string
|
|
|
|
field :link_text, :string
|
|
field :created_at, :integer
|
|
end
|
|
|
|
def changeset(link, attrs) do
|
|
link
|
|
|> cast(attrs, [:id, :source_post_id, :target_post_id, :link_text, :created_at])
|
|
|> validate_required([:id, :source_post_id, :target_post_id, :created_at])
|
|
|> foreign_key_constraint(:source_post_id)
|
|
|> foreign_key_constraint(:target_post_id)
|
|
end
|
|
end
|