soft delete - identity issue
i have a resource, for which soft delete is on, the resource has a field: :deleted_at.
If I do not add this field to the identity, on creation the data is validated to be unique, but if I (soft) delete a record, than I can not create another one with the same unique fields.
If I add the field to the identity, on creation the data is not validated correctly, since it includes the deleted_at null field.
I created a template project back then without ash for the soft delete and historization, and someone told me to add the nulls_distinct: false option, and it will solve the problem.
I also found the same config option in ash, and added nils_distinct?: false.
Now it looks good for checking uniqueness upon creation, and I can also delete a resource, but only once.
Somehow the deleted_at uniqueness should be - according to my understanding - unique on the timestamp basis, but it still gives me this error upon save:
Form Error: [
%Ash.Error.Changes.InvalidAttribute{
field: :deleted_at,
message: "Supplier price already exists for this configuration",
private_vars: [
constraint: :unique,
constraint_name: "supplier_prices_unique_supplier_price_index"
],
value: nil,
splode: Ash.Error,
bread_crumbs: [],
vars: [],
path: [],
stacktrace: #splode.Stacktrace<>,
class: :invalid
}
2 Replies
Make a calculation called
soft_deleted?
(or is_soft_deleted
for example, whatever you want) and use that in the identity. You will get an error message should guide you to how to configure the Postgres section to support itThanks, will try that!