1
因此,按照在外生文檔的例子,我有以下幾點:如何在many_to_many關聯中添加和刪除關係?
defmodule Post do
use Ecto.Schema
schema "posts" do
many_to_many :tags, Tag, join_through: "posts_tags"
end
end
和
defmodule Tag do
use Ecto.Schema
schema "tags" do
many_to_many :posts, Post, join_through: "posts_tags"
end
end
現在有哪些不同的方式:
一)關聯現有發佈一個現有的標籤。
b)從標籤取消關聯現有帖子。
注意我不想創建一個嵌套的資源,但情況是我有一個%Post{}
和一個tag_id
,我希望創建或銷燬它們之間的關聯。