Skip to content

Instantly share code, notes, and snippets.

@marinho10
Last active January 31, 2019 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinho10/9730c4b93fed0e52a2262233f08b31f3 to your computer and use it in GitHub Desktop.
Save marinho10/9730c4b93fed0e52a2262233f08b31f3 to your computer and use it in GitHub Desktop.
def upsert_user_projects(user, project_ids) when is_list(project_ids) do
projects =
Project
|> where([project], project.id in ^project_ids)
|> Repo.all()
with {:ok, _struct} <-
user
|> User.changeset_update_projects(projects)
|> Repo.update() do
{:ok, Accounts.get_user(user.id)}
else
error ->
error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment