Saving has_many from array

I want to provide an array with ids of some blobs. I have the following schema:
defmodule News do

schema “news” do

has_many :documents, News.Document, foreign_key: :news_id

The document model is:
defmodule News.Document do
@moduledoc false
use Web, :model
schema “news_documents” do
belongs_to :news, News
belongs_to :blob, Blobs.Blob



and the changeset options:
def changeset(struct, params \ %{}) do
|> cast(params, [:headline, …])
|> validate_required([:headline])

Do I need to save the news_documents before or can this be done in one step or what exactly do I have to do?

i dont know what u are trying to achieve . But maybe u are looking for, create news documents, and news with same form. We call that nested forms

Seems my approach was completly wrong. Was working a long time with Hibernate and EntityFramework. Ecto makes it a bit more difficult. I now choose an other approach and create my documents in a seperate step. Had to add a new controller action to save the documents and added the documents as relationships to the news view (json api… hate it :wink: but works now. Thanks for the answer.

Thread can be closed