[thelist] Constraint/trigger help

Matt Warden mwarden at gmail.com
Fri May 18 14:14:59 CDT 2007


> How can I ensure (in the database) that default_mailbox
> references a mailbox that has its owner set to the same user?

I have to question the model a little. Is default_mailbox really an
attribute of a user? The fact that you have owner in the mailbox table
suggests that you agree that the relationship to the user really makes
more sense as an attribute of the mailbox than it does the other way
around.

I think you store whether a given mailbox is the default mailbox in
the mailbox table.

Then, your question becomes: do I want to have a check in the database
to make sure that there is only one default mailbox per group, where a
group is defined by the owner?

I personally think this is business logic and should be in the
application code. However, if you disagree, then you could use a check
clause or trigger. Note that this will slow down inserts, which can be
a significant problem if you ever do any kind of batch loading.

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list