feat: more completeness of spec and start at embedding
This commit is contained in:
25
lib/bds/posts/link.ex
Normal file
25
lib/bds/posts/link.ex
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user