feat: more completeness of spec and start at embedding

This commit is contained in:
2026-04-24 07:57:28 +02:00
parent d04117abdc
commit 88f966dae9
10 changed files with 1105 additions and 32 deletions

25
lib/bds/posts/link.ex Normal file
View 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