I have a changeset that should fail because of foreign_key_constraint
. When I run Ecto.Repo.insert(changeset)
I get
{:error,
#Ecto.Changeset<
action: :insert,
changes: %{
binding_source: :github,
org_id: "55074a5d-a394-485d-b4c7-3d8156db59dc",
project_id: "55074a5d-a394-485d-b4c7-3d8156db59dc",
role_id: "55074a5d-a394-485d-b4c7-3d8156db59dc",
subject_id: "55074a5d-a394-485d-b4c7-3d8156db59dc"
},
errors: [
role_id: {"does not exist",
[
constraint: :foreign,
constraint_name: "subject_role_bindings_role_id_fkey"
]}
],
data: #Guard.Repo.SubjectRoleBinding<>,
valid?: false
>}
which is expected. But, when I run
Ecto.Multi.new()
|> Ecto.Multi.insert(
:insert_name,
changeset
)
|> Ecto.Repo.transaction()
I get {:ok, %{}}
, and no error is raised.
According to this documentation, Ecto.Multi.insert should raise errors from changeset before starting the transaction.
Does anyone know whats the problem here? Thanks