Alternera. Resource. Changes. CheckTenantReferences
(alternera_resource_sdk v0.9.0)
Copy Markdown
View Source
On every create and update: a belongs_to that names a record of another
tenant is refused with an error on that field.
The tenant-matched foreign key (Transformers.AddTenantReferences)
refuses the write in the database. AshPostgres reports that on the
referencing field for a create, but on an update of a resource that
references itself the constraint is the same on both ends, and the error
reads "would leave records behind" on the primary key. This change turns
that error, after the transaction, into one on the reference fields the
write set, saying they name no record of this tenant. It runs after the
transaction rather than before the write so that updates stay atomic.