Ecto.build_assoc does not trigger changeset function

No, the latter code you have (Repo.get_by!(Accounts.Organizations, id: 1) |> Ecto.build_assoc(:applications, name: "My New App") |> Repo.insert!) is interacting directly with the Repo/Ecto interfaces, that’s at a lower level than using your changeset.

To use your changeset you would need to be using cast_assoc and Handling nested associations with cast_assoc might help you here too.

1 Like