Doctrine Relations and Data Fixtures




Zend Screencasts: Video Tutorials about the Zend PHP Framework  (iphone) show

Summary: <p>This episode of zendcasts will cover how we can write Data Fixtures and extend our data model to include a simple one-to-many using Doctrine’s schema.yml file. I also noticed in the code of my last example that Model loading wasn’t working properly. I cover the fix in the video, however I’d like to highlight it here too. In your _initDoctrine() method, make sure you load the models:<br> Doctrine::loadModels($doctrineConfig['models_path']);</p> <p>also, I’d like to extend a welcome to the folks at <a href="http://www.servergrove.com/">ServerGrove Networks</a> for sponsoring this episode of Zendcasts. ServerGrove specializes in Zend Framework hosting and they’ve offered a 10% rebate on hosting with coupon code “<strong>zc</strong>“. If you’re looking for a host, be sure to <a href="http://www.servergrove.com/">check them out</a>.</p> <p>Grab a <a href="http://zendcasts.googlecode.com/svn/trunk/zc40-doctrine-data-fixtures-and-relations/zc40-doctrine-data-fixtures-and-relations.zip">copy of the project</a> or <a href="http://code.google.com/p/zendcasts/source/browse/#svn/trunk/zc40-doctrine-data-fixtures-and-relations">browse the repository</a>.</p> <p><strong>Edit:</strong> I spoke to Guilherme Blanco (one of the core developers behind Doctrine) and he kindly brought up some things I should bear in mind for my Doctrine / Zend set.<br> Doctrine’s autoloader configuration <a href="http://www.doctrine-project.org/upgrade/1_2#PEAR%20Style%20Model%20Loading%20and%20Generation">can be scaled back by doing PEAR style Model Loading (new to 1.2)</a>. Also, you can use Doctrine_Core instead of Doctrine since everything has been moved to Doctrine_Core in order to follow Zend-style namespacing.</p> <p>lastly, you can register your own CLI tasks as part of Doctrine’s CLI script or just write them in the scripts/doctrine.php file. With this, you could have your newly-generated models placed in the necessary folders. I’ll be experimenting with this in the coming week.</p>