Swank Wiki
Recently Visited

Swank v0.04.04


This is a module which will support any needed integrity constraints.

Currently, there is just a uniqueness constraint implemented, called check_duplicate.


Swank::Lucene, Swank::Error


$page->check_duplicate( [action=>'toss',] 'field1', ['field2, ...] );

This new method is added to the Swank::Page base object.  Pages can call this, usually, in the validate action to ensure the page is not duplicated for the given fields.  The given fields will thus be a unique index for the pages.  ('swank_type' is a good field to include in the list.)

If a duplicate page is found, the specified action will be taken and the duplicate page is returned to the caller.  Possible actions are:

toss: This is the default.  An exception is tossed (see Swank::Error), which usually causes the save to fail and the error to be displayed to the user.

overwrite: The duplicate page is overwritten with this page.

merge: The duplicate page is merged with this page.  If they have different values for the same key, this page's values will take precedence.

return: No error is thrown.  The duplicate page is still returned to the caller.  If the caller does nothing else in the validate action, a duplicate record will be created.  But this action could be useful for finding duplicates outside the validate action.

(It is still possible for duplicates to go undetected if two records are created at the same time on a busy server.  If the second record checks for duplicates before the first record is indexed, the duplicate will not be detected.)


A routine to do cascading deletes is planned for the future.

Maybe a foreign key check would be useful?