Project

General

Profile

Feature #851

Record classes should have hooks for verification before saving

Added by Elmer de Looff over 12 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Elmer de Looff
Category:
Model
Target version:
Start date:
2012-06-06
Due date:
% Done:

100%

Estimated time:
Spent time:

Description

Record classes on the model should have hooks to:
  • Verify the record data is valid for insertion into the database
  • Convert data from and to database-safe values, different from Python runtime use

Related issues

Related to µWeb - Feature #840: Model documentation updatesNew2012-05-31

Associated revisions

Revision 238:ea565870604a (diff)
Added by Elmer de Looff over 12 years ago

Updated the uWeb database model to provide hooks before and after creation and saving, and upon loading from the database. This resolves #851.

Revision 239:09ce69c7f119 (diff)
Added by Elmer de Looff over 12 years ago

Fixed a small number of inconsistencies and errors. Moved relational oriented function calls away from BaseRecord to Record and MongoRecord separately. This refs #851.

History

#1 Updated by Elmer de Looff over 12 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 70

Applied in changeset ea565870604a.

#2 Updated by Elmer de Looff over 12 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 70 to 100

This has been implemented and confirmed to work. MongoRecord and VersionedRecord now also do not write to the database when no changes have occurred. This reduces the potential number of database actions.

#3 Updated by Elmer de Looff over 12 years ago

The provided hooks are:

  • _PreCreate will run before a record is inserted into the database using the Create method.
  • _PostCreate will run after a record is inserted into the database using the Create method.
  • _PreSave will run when the Save method is used, right before the database is updated. This method will only trigger if changes have been made.
  • _PostSave will run after the database has been updated (through the Save method. This method will only trigger if changes have been made.

N.B.: For subclasses of Record, the above methods will be called inside the database transaction. The currently open cursor will be provided for the methods to query the database with, as opening new transactions is not possible. MongoRecord will not be provided a cursor instance (but will not have the transaction limitation).

Additionally, there is the _PostInit method, which will run after an object is initialized. This means that objects loaded from the database can be transformed by _PostInit. This method will not run for Record instantiated through Create (use _PreCreate for those). This method is not part of a transaction, and will therefor not get a cursor instance provided.

Also available in: Atom PDF