Skip to content

Instantly share code, notes, and snippets.

@b0oh
Created July 18, 2018 09:09
Show Gist options
  • Select an option

  • Save b0oh/2e5dc73d5c74841708dc0ca5fef66630 to your computer and use it in GitHub Desktop.

Select an option

Save b0oh/2e5dc73d5c74841708dc0ca5fef66630 to your computer and use it in GitHub Desktop.
Upsert
changeset =
ProviderSelection.upsert_changeset(%{
entity_id: entity_id,
entity_type: entity_type,
provider: provider
})
set_values =
changeset.changes
|> Keyword.new()
on_conflict =
ProviderSelection
|> update(set: ^set_values)
insert_options = [
conflict_target: [:entity_id, :entity_type],
on_conflict: on_conflict
]
Repo.insert!(changeset, insert_options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment