[LRUG] Enforcing uniqueness

Mark Woods mwoods at online.ie
Fri Nov 11 07:25:13 PST 2011


> Any ideas?

Assuming you can't create a conditional unique index because your dbms
doesn't support it...

Maybe I'm missing something, but couldn't you just use a before_save
callback to double-check that a loan is unique, raising an exception
if not, thereby triggering a rollback of the current transaction?

Alternatively, you could probably use a unique constraint applied to
multiple columns if you used some non-null value to indicate that a
loan is current (this is probably ugly, unless you already have some
flag like that, which you probably don't, and probably shouldn't add
to work around an issue like this).

You could also create a before trigger on the database table that
prevents an insert from succeeding unless the loan is unique (also
ugly).


Mark



More information about the Chat mailing list