Hey peeps. Has anybody used Ecto.Changeset.unsafe_validate_unique
with an association? I’m trying to do something like this:
organization = Repo.get!(Organization, 1)
%User{}
|> Ecto.Changeset.cast(%{email: "email", pass: "pass"}, [:email, :pass])
|> Ecto.Changeset.put_assoc(:organization, organization)
|> Ecto.Changeset.unsafe_validate_unique([:email, :org_id], MyApp.Repo)
I read the implementation of unsafe_validate_unique
and the query doesn’t know how to handle associations. It only adds a simple where clause for chosen fields. Here’s the link to the implementation: ecto/changeset.ex at 599a1a327b78320f85551c62b14fb7d272439014 · elixir-ecto/ecto · GitHub
In my case, I don’t want to cast the org_id
, since that’s not something that should come directly from the user. Has anybody run into something similar? I feel like that would be a very common scenario for any type of SaaS type of app.