Author: sergiovier Date: 2010-04-20 20:22:03 +0200 (Tue, 20 Apr 2010) New Revision: 29225
Modified: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php Log: added support for doctrine < 1.2 Modified: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README =================================================================== --- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README 2010-04-20 16:41:07 UTC (rev 29224) +++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README 2010-04-20 18:22:03 UTC (rev 29225) @@ -9,19 +9,33 @@ This plugin is based on the work of Leon van der Ree and your plugin [sfPropelObjectPathBehaviorPlugin](http://www.symfony-project.org/plugins/sfPropelObjectPathBehaviorPlugin). -Note: this plugin implement only a left join union. Other types are not supported yet. +Doctrine version 1.2 is fully supported. For Doctrine version 1.0 and 1.1 there are some restrictions (it's not possible set up a customized query class) with the use of [sfDataSourcePlugin](http://www.symfony-project.org/plugins/sfDataSourcePlugin). -## Installation +Note: this plugin implement only a left join union. Other types are not supported yet. + +## Installation ## + 1.Download and install the plugin ./symfony plugin:install sfAlyssaSmsPlugin + +2.Check that sfAlyssaDoctrineObjectPathPlugin is enabled before sfDoctrinePlugin. -2.Clear the cache + [php] + public function setup() + { + $this->enablePlugins('sfAlyssaDoctrineObjectPathPlugin'); + $this->enablePlugins('sfDoctrinePlugin'); + ... + } +3.Clear the cache + ./symfony cc + ## Example ## So a very simple ObjectPath from City to Country is simply "Country" and from Country to City it would be "City": @@ -36,28 +50,44 @@ [php] $query = Doctrine_Query::create(); $reviews = $query-> + from('Review')-> joinByObjectPath('Book.Author')-> orderByProperyPath('Book.Author.FirstName asc')-> excecute(); to find all reviews, left joined with their Books, left joined with their Authors. + +For Doctrine 1.0 and 1.1, the php-code look like: + + [php] + $query = sfAlyssaDoctrineQuery::create(); + $reviews = $query-> + from('Review')-> + joinByObjectPath('Book.Author')-> + orderByProperyPath('Book.Author.FirstName asc')-> + excecute(); + +in this case, we need an instance of 'sfAlyssaDoctrineQuery' customized doctrine query class. + There are some extra methods working with PropertyPaths: [php] $query = Doctrine_Query::create(); $reviews = $query-> + from('Review')-> joinByObjectPath('Book.Author')-> whereByProperyPath('Book.Author.FirstName = ?', 'Sergio')-> orderByPropertyPath('Book.Title')-> excecute(); -similar to previous query, but filtering by FirstName property of Author and ordering by Title property of Book. +similar to previous query for Doctrine 1.2, but filtering by FirstName property of Author and ordering by Title property of Book. + ## Note ## -The sfAlyssaDoctrineObjectPathPlugin is used in the [sfDataSourcePlugin](http://www.symfony-project.org/plugins/sfDataSourcePlugin), but not required. +The sfAlyssaDoctrineObjectPathPlugin is also used in the [sfDataSourcePlugin](http://www.symfony-project.org/plugins/sfDataSourcePlugin), but not required. Modified: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php =================================================================== --- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php 2010-04-20 16:41:07 UTC (rev 29224) +++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php 2010-04-20 18:22:03 UTC (rev 29225) @@ -52,11 +52,17 @@ */ public function configureDoctrine(sfEvent $event) { - $manager = $event->getSubject(); - if ('Doctrine_Query' == $manager->getAttribute(Doctrine_Core::ATTR_QUERY_CLASS)) - { - $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CLASS, 'sfAlyssaDoctrineQuery'); + // configure Doctrine_Query class only supported in Doctrine >= 1.2 + if (strpos(Doctrine::VERSION, '1.2') !== false){ + + $manager = $event->getSubject(); + + if ('Doctrine_Query' == $manager->getAttribute(Doctrine::ATTR_QUERY_CLASS)) + { + $manager->setAttribute(Doctrine::ATTR_QUERY_CLASS, 'sfAlyssaDoctrineQuery'); + } + } } Modified: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php =================================================================== --- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php 2010-04-20 16:41:07 UTC (rev 29224) +++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php 2010-04-20 18:22:03 UTC (rev 29225) @@ -22,6 +22,28 @@ const ALIAS_DELIMITER = '___'; /** + * create + * returns a new Doctrine_Query object + * + * @see Doctrine_Query::create() + * + * @param Doctrine_Connection $conn optional connection parameter + * @param string $class Query class to instantiate + * @return Doctrine_Query + */ + public static function create($conn = null, $class = null) + { + // Doctrine < 1.2 does not support customized query class + // and factory method "create" brings only a Doctrine_Query instance. + if (strpos(Doctrine::VERSION, '1.2') === false){ + return new sfAlyssaDoctrineQuery($conn); + } + + return parent::create($conn, $class); + + } + + /** * Recursively performs join on the provided ObjectPaths * * @param mixed $objectPath one or more strings with objectPaths -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
