I see that in changelogs [Ecto.Changeset] Raise when schemaless changeset or embedded schema is used in unsafe_validate_unique/4. but i dont understand reasoning. Why wouldn’t unsafe_validate_unique validation be allowed if query base is provided?
I sthis considered a bug, or it will stay this way and i need to create custom validation for this.
My 5 cents would be that for UNSAFE_validation_unique passing custom query base should be an option.
Previously i was passing query as option (..., query: Query.base(), ...), that had table with some specific where clauses and joins to make sure uniqueness is constrained only within specific scope.
Query option: the base query to use for the check. Defaults to the schema of the changeset. If the primary key is set, a clause will be added to exclude the changeset row itself from the check.
but now custom source can be provided only for schemas (that already have source) if necessary, but not for schemaless. I would expect that for schemaless query option should be required tho.
I think this is a case of someone running into unsafe_validate_unique not working on embedded schemas without a custom query. The handling of that got improved, but went a bit too far, as using a custom :query might be a legitimate usecase. I’d open an issue and see if the added error can be loosened a bit.