Please note: this project is inactive since early 2006

3.2.2 Within classes

A class corresponding to an entity must meet the following requirements:

Inheritance:
the class must include CustomObject in its inheritance list

Initializer:
the method __init__() should be designed so that it is possible to call it with no arguments at all: for example, if the method accepts arguments, each one should have default values. The reason for this is that the framework relies on a call to __init__() without any arguments, when it needs to create an instance before populating it with data fetched from the database.

Entity's name:
the class must define a method entityName() taking no argument: this is the way the framework currently binds an object to its entity. This should be changed (see TODO)

willRead():
this method defined in CustomObject must be called prior to accessing an object's property3.2. It informs the object that it is time to fetch the values stored in the database if it's not done yet. This is because objects can be ``faults'' (ZODB speaking, they are ghosts), i.e. they have been instantiated but not fully initialized yet (lazily initialization)

willChange():
defined in CustomObject as well, this method should be called prior to modifying an object's property. This is part of the Observing interface, and its purpose is to notify the EditingContext that the object is about to change: the EditingContext needs to keep track of changes in its graph of objects in order to be able to save the changes (ZODB speaking, this is what the mix-in class Persistent does transparently for immutable attributes (see also: TODO)).

Of course, willChange automatically invokes willRead.

Getters, setters:
although the python code derived from a model stores its properties in attributes beginning with an underscore (for example, _lastName for attribute lastName), the framework itself does not require this. Instead, it accesses and sets the values using the so-called private API of KeyValueCoding; shortly said, this means that in order to read a property 'name' for example, it tries to find either an attribute or a method called '_name', '_name()', '_getName()', 'name', 'getName()'. Refer to 8.2 for a complete overview.

Warning: It is your responsability to call willRead and willChange when you are about to, respectively, access or change an object's property corresponding to a Model's Attribute or Relationship; if you do not, the EditingContext, which is responsible for examining the changes and making them persistent, is likely to do only part of its job, possibly resulting in objects being partially saved, or not at all.



Footnotes

... property3.2
i.e. either an attribute or a relationship defined in the entity
Comments are welcome: Sebastien Bigaret / Modeling Home Page
Hosted by:SourceForge.net Logo