{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/1040","labels_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1040/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1040/comments","events_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1040/events","html_url":"https://github.com/elixir-lang/ecto/pull/1040","id":112861148,"number":1040,"title":"Add insert_or_update","user":{"login":"mschae","id":473241,"avatar_url":"https://avatars.githubusercontent.com/u/473241?v=3","gravatar_id":"","url":"https://api.github.com/users/mschae","html_url":"https://github.com/mschae","followers_url":"https://api.github.com/users/mschae/followers","following_url":"https://api.github.com/users/mschae/following{/other_user}","gists_url":"https://api.github.com/users/mschae/gists{/gist_id}","starred_url":"https://api.github.com/users/mschae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mschae/subscriptions","organizations_url":"https://api.github.com/users/mschae/orgs","repos_url":"https://api.github.com/users/mschae/repos","events_url":"https://api.github.com/users/mschae/events{/privacy}","received_events_url":"https://api.github.com/users/mschae/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-22T18:21:20Z","updated_at":"2015-10-23T07:23:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elixir-lang/ecto/pulls/1040","html_url":"https://github.com/elixir-lang/ecto/pull/1040","diff_url":"https://github.com/elixir-lang/ecto/pull/1040.diff","patch_url":"https://github.com/elixir-lang/ecto/pull/1040.patch"},"body":"As discussed on the [Elixir-Ecto mailing list](https://groups.google.com/forum/#!topic/elixir-ecto/xCkbwhViE8s) here is a PR to add `Ecto.Repo.insert_or_update/2` and `Ecto.Repo.insert_or_update/2`."},"comment":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/comments/150496181","html_url":"https://github.com/elixir-lang/ecto/pull/1040#issuecomment-150496181","issue_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1040","id":150496181,"user":{"login":"michalmuskala","id":477062,"avatar_url":"https://avatars.githubusercontent.com/u/477062?v=3","gravatar_id":"","url":"https://api.github.com/users/michalmuskala","html_url":"https://github.com/michalmuskala","followers_url":"https://api.github.com/users/michalmuskala/followers","following_url":"https://api.github.com/users/michalmuskala/following{/other_user}","gists_url":"https://api.github.com/users/michalmuskala/gists{/gist_id}","starred_url":"https://api.github.com/users/michalmuskala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalmuskala/subscriptions","organizations_url":"https://api.github.com/users/michalmuskala/orgs","repos_url":"https://api.github.com/users/michalmuskala/repos","events_url":"https://api.github.com/users/michalmuskala/events{/privacy}","received_events_url":"https://api.github.com/users/michalmuskala/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T07:23:38Z","updated_at":"2015-10-23T07:23:38Z","body":"This would be solved if we could use upsert on the database level, unfortunately postgres does not support it (yet). This is basically doing upsert on the client side.\r\n\r\nI definitely prefer `insert_or_update` rather than `save`.\r\nWhen it comes to changesets - shouldn’t we try to use the `action` field before going with the state from the model? We should probably also mention the `Ecto.Model.put_meta` function in the documentation."}}