Identity on `attribute :some_attribute, {:array , EmbeddedResource}`
So if I have the following resource.
And the following embedded resource.
If I do the following changeset twice.
It succeeds once and then fails a second time, which is as expected. The
:unique_some_attribute
identity prevents two records with some_attribute: nil
. However If the next changeset is repeated twice.
Two resources with the same :some_attribute
field are created. I had hoped this to be prevented by the :unique_some_attribute
identity.
The resulting records look something like the following.
I assume the autogenerated_id
fields being unique is preventing the desired outcome. Would that work and can they be disabled?3 Replies
identities
on embedded resources are only applied within lists of that attribute, not all instances of the embedded resource
Its unlikely that would ever be supported automatically
If you want to ensure that you have uniqueness in that way you would need to do something else, some options:
1. make that a resource and relationship. If you want cross-record uniqueness, it seems natural to me that this thing you're creating is not really an embedded resource (scoped to parent) but a regular resource
2. implement some kind of custom validation that checks for conflicts before committing
3. implement some database level constraintI'm not sure how I would do so with a resource and relationship. Regardless thanks for the response.
What I mean is that instead of using an embedded resource, you'd make a regular resource
and then do:
Then if you put an identity on that related thing you'll have global uniqueness