Database schemas

The Doctrine ORM framework provides a basic facility, the Doctrine_Record class, to access, create and modify a unique record in a table. On the other hand, it is helpful to have a flexible table definition and this is where XML schemas come into play. Inspired by MDB2_Schema, a schema facility was implemented in Doctrine and Jaws takes advantage of it in a very peculiar way.


Since our schema definitions are flexible and will be modified in time, using the Doctrine_Import_Xml::importObj() function is not an option, as it creates a new file with an exmpty class each time we modify the schema, meaning we'd have to copy our methods and everything else all the time. No way !

Instead, we'll use the Doctrine_Import_Builder::getDef() method, which returns a string containing what would have been put in the setTableDefinition() function if we would've used the Doctrine_Import_Xml::importObj() method.

The class will be store in a file called [Classname].php.tpl and must contain ONCE the tag %HEREOBJDEF%, which will be replaced by the object definition. That's how we can keep our class definition independant of the table schema.

How is it done ?

Before shipping a release, it is obvious we'll have to "pre-process" the .tpl record files so we get usable .php files. This is done through a method called Jaws_Db_Schema::installRecords(). To have a .tpl file compiled by that function, it has to be included into the $toInstall array. See include/Jaws/Jaws/Db/Schema.php for more details.

< Click here to go back to Jaws 2 section