When dealing with a 1:N relationship between diaries and photos, I would like to know how to create a diary in such a way that its associated photos are also simultaneously generated. What would be the appropriate approach or method for achieving this?
diary resource
---
actions do
defaults [:read, :update, :destroy]
create :create do
argument :photos, {:array, :map}
primary? true
change manage_relationship(
:photos,
type: :create
)
end
end
relationships do
has_many :photos, DiaryPhoto
end
end
diary_photo resource
...
relationships do
belongs_to :diary, Diary do
attribute_writable? true
end
end
code
Diary
|> Ash.Changeset.for_create(:create,
%{title: "diary title",
...
},
photos: [
%{
file_name: "name",
url: "url"
},
%{
file_name: "name",
url: "url"
},
])
|> Diary.create()
When running the above code, only the diary is created.
The photo resources are not being created.
I would like the photos to be created along with it.