Created
June 14, 2019 09:38
-
-
Save Copser/254972bc533327d7a6c9ad94b9a8547a to your computer and use it in GitHub Desktop.
many to many associations ecto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = Repo.get!(User, user_id) |> Repo.preload(:roles) | |
role = Repo.get!(Role, role_id) | |
user_changeset = Changeset.change(user) |> Changeset.put_assoc(:roles, [role | user.roles]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment