Feature #851
Record classes should have hooks for verification before saving
Description
- 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
Associated revisions
Revision 239:09ce69c7f119
(diff)
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 13 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 13 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 13 years ago
The provided hooks are:
_PreCreatewill run before a record is inserted into the database using theCreatemethod._PostCreatewill run after a record is inserted into the database using theCreatemethod._PreSavewill run when theSavemethod is used, right before the database is updated. This method will only trigger if changes have been made._PostSavewill run after the database has been updated (through theSavemethod. 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.
Updated the uWeb database model to provide hooks before and after creation and saving, and upon loading from the database. This resolves #851.