Yes, though the reverse-engineering mechanism is slightly broken in certain situations. However I’m fixing it right now and you can see my note at the bottom if you encounter this known issue...
But anyway, here is a generic version of the build file for the MODx 0.9.7 model. To forward-engineer your database, just tailor the reverse-engineered xml file (the schema) you generate, then comment the reverse-engineering line and uncomment the forward-engineering line; that will generate the classes and maps of your object model and provide the basic scaffolding for working with those objects (i.e. CRUD, or ACID, or basically just be able to manage individual instances as rows in a database).
Please note, the resulting XML schema is incomplete; you will need to define relationships between the various objects in the schema to take full advantage of xPDO. I’ll post another topic on this issue...
<?php
$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tstart= $mtime;
include_once (strtr(realpath(dirname(__FILE__)) . '/../xpdo.class.php', '\\', '/'));
$xpdo= new xPDO('mysql:host=localhost;dbname=mydb', 'user', 'password', 'optional_tbl_prefix_');
$xpdo->setPackage('mymodel');
$xpdo->setDebug(true);
$manager= $xpdo->getManager();
$generator= $manager->getGenerator();
//reverse-engineer an existing database
//$xml= $generator->writeSchema(XPDO_CORE_PATH . '_model/mymodel.mysql.schema.xml', 'mymodel', 'xPDOObject', 'optional_tbl_prefix_');
//forward-engineer a model
$generator->parseSchema(XPDO_CORE_PATH . '_model/mymodel.mysql.schema.xml');
$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tend= $mtime;
$totalTime= ($tend - $tstart);
$totalTime= sprintf("%2.4f s", $totalTime);
echo "\nExecution time: {$totalTime}\n";
exit ();
I usually create this in a folder called _model under my xpdo directory, for convenience.
BTW, the bug is it will put AUTO_INCREMENT as an element directly in columns with that attribute if you have not named them ’id’ specifically. To fix this, simply replace the AUTO_INCREMENT string it erroneously inserts with the following line:
generated="native" attributes="unsigned"
NOTE: obviously, if you allow signed values in an AUTO_INCREMENT column, you are insane... and if so, just don’t include that part.