[jifty-devel] Referential integrity

Edmund von der Burg evdb at ecclestoad.co.uk
Thu Mar 8 09:40:01 EST 2007


I want to create a setup where it is not possible to delete an object
in one class if it is being referenced from another class. Eg say I
have boks and authors, I want to prevent deletion of an author if
there are books by that author in the database.

What is the best way to do this?

I could add foreign key links in the database but that might not be
portable (I am on postgres).

I could add code to each model class to check before deleteing but
that would be cumbersome. Rather I'd like Jifty to enforce this sort
of relationship if a 'references' column is marked as 'mandatory'. ie
in Book.pm the 'author' would be marked as 'is mandatory'. Hence
deleteing the books author would leave the book in an invalid state so
the deletion of the author should be prevented.

Am I missing something?


In reality I'm evdb at ecclestoad.co.uk - http://ecclestoad.co.uk

More information about the jifty-devel mailing list