I have this schema:
schema "rooms_units" do
field(:date_from, :utc_datetime)
field(:date_to, :utc_datetime)
belongs_to(:room, App.Room, primary_key: true)
belongs_to(:unit, App..Unit)
end
In my function I am making list of changesets and pass the list to Multi.insert_all
as the room_unit_changeset
Multi.new
|> Multi.insert_all(:room_units, Appr.RoomUnit ,room_unit_changeset)
|> Repo.transaction()
Multi.insert_all
returns the output like this:
%Ecto.Multi{
names: #MapSet<[:room_units]>,
operations: [
rooms: {:insert_all, App.RoomUnit,
[
#Ecto.Changeset<
action: nil,
changes: %{
date_from: #DateTime<2016-11-03 13:23:00Z>,
date_to: #DateTime<2016-11-03 13:23:00Z>,
room_id: 9,
unit_id: 14
},
errors: [],
data: #App.RoomUnit<>,
valid?: true
>,
#Ecto.Changeset<
action: nil,
changes: %{
date_from: #DateTime<2016-11-03 13:23:00Z>,
date_to: #DateTime<2016-11-03 13:23:00Z>,
room_id: 10,
unit_id: 14
},
errors: [],
data: #App.RoomUnit<>,
valid?: true
>,
], []}
]
}
But Repo.transaction
is not working. Returning the server error .
Any help will be much appreciated
thanks