Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create the user. Note that the (empty) `organizations` field has to be preloaded.
- user_map = %{display_name: "User 1", login_name: "1@y.com", password: "password"}
- changeset = User.password_setting_changeset(%User{}, user_map)
- user = Repo.insert!(changeset) |> Repo.preload(:organizations)
- # Do the same for the organization:
- org = %Eecrit.Organization{short_name: "org1", full_name: "Organization 1"}
- org = Repo.insert!(org) |> Repo.preload(:users)
- # Update one of the two of them:
- changeset = Ecto.Changeset.change(user) |> Ecto.Changeset.put_assoc(:organizations, [org])
- # "When you save this change to the user, the join table will have its foreign keys populated in both directions."
- Repo.update!(changeset)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement