Saving has_many from array

Hi,
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
timestamps()
end

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

  timestamps()
end

end

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

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?
Thanks.

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

http://lesseverything.com/blog/nested-forms-in-phoenix/

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