{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/534","labels_url":"https://api.github.com/repos/elixir-lang/ecto/issues/534/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/ecto/issues/534/comments","events_url":"https://api.github.com/repos/elixir-lang/ecto/issues/534/events","html_url":"https://github.com/elixir-lang/ecto/issues/534","id":63462348,"number":534,"title":"Uniqueness scope","user":{"login":"hunterboerner","id":1314119,"avatar_url":"https://avatars.githubusercontent.com/u/1314119?v=3","gravatar_id":"","url":"https://api.github.com/users/hunterboerner","html_url":"https://github.com/hunterboerner","followers_url":"https://api.github.com/users/hunterboerner/followers","following_url":"https://api.github.com/users/hunterboerner/following{/other_user}","gists_url":"https://api.github.com/users/hunterboerner/gists{/gist_id}","starred_url":"https://api.github.com/users/hunterboerner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hunterboerner/subscriptions","organizations_url":"https://api.github.com/users/hunterboerner/orgs","repos_url":"https://api.github.com/users/hunterboerner/repos","events_url":"https://api.github.com/users/hunterboerner/events{/privacy}","received_events_url":"https://api.github.com/users/hunterboerner/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elixir-lang/ecto/labels/Kind:Enhancement","name":"Kind:Enhancement","color":"207de5"},{"url":"https://api.github.com/repos/elixir-lang/ecto/labels/Level:Intermediate","name":"Level:Intermediate","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-03-21T22:47:21Z","updated_at":"2015-05-01T09:19:01Z","closed_at":null,"body":"To check for uniqueness with a scope something like this: `where: field(m, ^scope) == ^scope_value` needs to be added to this query https://github.com/elixir-lang/ecto/blob/d8034fd15da4202d8c9925420ef24cd174120274/lib/ecto/changeset.ex#L745\r\n\r\nThose two vars can be obtained with: \r\n\r\n```\r\nscope = opts[:scope]\r\nscope_value = Map.get(params, Atom.to_string(scope)) || Map.get(model, scope)\r\n```"},"comment":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/comments/98084209","html_url":"https://github.com/elixir-lang/ecto/issues/534#issuecomment-98084209","issue_url":"https://api.github.com/repos/elixir-lang/ecto/issues/534","id":98084209,"user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"created_at":"2015-05-01T09:19:01Z","updated_at":"2015-05-01T09:19:01Z","body":"I think the previous approach is fine. We should do:\r\n\r\n     opts[:scope] || model.__struct__\r\n\r\nI don't think we need to worry about having different sources because queries are usually built starting from the source (i.e. it is very hard to start a query without a source)."}}