You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, if within the same form, I were to toggle primary off of the first record and toggle it on on the second record, the save would fail because it violates the unique constraint. I would need to turn all primary switch off first, then save, then re-edit and toggle on the new one.
With postgres there are deferred constraint that can wait until the end of a transaction before executing. This is supported since Rails 7.1. Indexes don't support deferrable but constraints do. Rewriting the previous index as a constraint would look like so:
add_exclusion_constraint:credentials,'"server_id" WITH =, "primary" WITH =',where: '"primary" = true',using: :btree,deferrable: :deferred
However, the gem is not able to find the appropriate index and raise DatabaseValidations::Errors::IndexNotFound.
Also, if both primary were to be off in database and I were to turn both ON in my form and then save, I would get an exception even with the rescue: :always
The text was updated successfully, but these errors were encountered:
Hi,
I have a case scenario where I can assign multiple credentials but only one can be set as "primary" for a server but any amount can be non-primary.
To reflect that, I could do
However, if within the same form, I were to toggle primary off of the first record and toggle it on on the second record, the save would fail because it violates the unique constraint. I would need to turn all primary switch off first, then save, then re-edit and toggle on the new one.
With postgres there are
deferred
constraint that can wait until the end of a transaction before executing. This is supported since Rails 7.1. Indexes don't support deferrable but constraints do. Rewriting the previous index as a constraint would look like so:However, the gem is not able to find the appropriate index and raise DatabaseValidations::Errors::IndexNotFound.
Also, if both primary were to be off in database and I were to turn both ON in my form and then save, I would get an exception even with the
rescue: :always
The text was updated successfully, but these errors were encountered: