<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.symforc.com/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>Symfony Resources Central - doctrine</title>
  <link>http://www.symforc.com/</link>
  <description>A place that groups many original symfony resources, along with my personal experiments of this great PHP5 MVC framework.</description>
  <language>en</language>
  <pubDate>Sat, 26 Jul 2008 19:34:33 +0200</pubDate>
  <copyright>All rights reserved</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Foreign key's onDelete for dummies</title>
    <link>http://www.symforc.com/post/2008/07/10/Foreign-keys-onDelete-for-dummies</link>
    <guid isPermaLink="false">urn:md5:2e49ed06a0bba3a3d2459d21260ff73d</guid>
    <pubDate>Thu, 10 Jul 2008 23:55:00 +0200</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>database</category>
        <category>database</category><category>doctrine</category><category>model</category><category>orm</category><category>propel</category>    
    <description>&lt;p&gt;Any modern relational database engine supports the onDelete and onUpdate attributes on foreign keys. Propel and Doctrine of
course allows to define it in the schema file (yaml or xml) and I believe it is important to explicitly set it.&lt;/p&gt;    &lt;h2&gt;Restrict mode&lt;/h2&gt;


&lt;p&gt;«Better do nothing than something stupid.»&lt;/p&gt;


&lt;p&gt;The default behaviour is &lt;em&gt;ON DELETE RESTRICT&lt;/em&gt;. This is the most secure setting, so it is normal to have it as default.&lt;/p&gt;


&lt;p&gt;If we try to &lt;em&gt;DELETE&lt;/em&gt; a record referenced by the current object, the database engine just raise an SQL error. If it was not
an error to &lt;em&gt;DELETE&lt;/em&gt; this, you will have to start by removing the linked object, or setting the foreign key value to something different.&lt;/p&gt;


&lt;h2&gt;Cascade mode&lt;/h2&gt;


&lt;p&gt;«No need to keep obsolete things.»&lt;/p&gt;


&lt;p&gt;But our database engines are able to do better. For example, if you have an user's settings table and you delete an user, you may not wan't
to keep his settings. You just set &lt;em&gt;ON DELETE CASCADE&lt;/em&gt; on user's setting foreign key column referencing the user table, and if a user is ever deleted, all his associated properties will be destroyed.&lt;/p&gt;


&lt;p&gt;Along with &lt;em&gt;ON DELETE CASCADE&lt;/em&gt;, we usually add a NOT NULL constraint (or required: true), as the existence of current object is directly
related to the existence of linked object. This may be wrong from time to time, but it is usually the case.&lt;/p&gt;


&lt;h2&gt;Set null mode&lt;/h2&gt;


&lt;p&gt;«We don't rely on this. Just forget it.»&lt;/p&gt;


&lt;p&gt;The last behavior is the &lt;em&gt;ON DELETE SET NULL&lt;/em&gt; option. It does exactly what it says. If linked object is removed, we set our foreign key
value to null.&lt;/p&gt;


&lt;p&gt;This the behavior you may want to use for articles having a link to their author for example. If the author is removed from database,
we don't want to delete his articles, so we just loose the author information (well ok, this is a simplification, but it basically shows
the idea).&lt;/p&gt;


&lt;h2&gt;Why I think we should explicitly use it&lt;/h2&gt;


&lt;p&gt;The default database engine behavior is «I don't know how to handle it». Setting it will add power to your database model, while taking
profit of your RDBMS features. Not setting it is like saying «I don't know which way I want my database to behave in case we delete a linked
object», and that's like saying «I don't know how I want my model to react». Thinking a little to understand which way you want it to work
will make you certain you're understanding the behavior you need in your project.&lt;/p&gt;


&lt;h2&gt;How to set it in your favorite ORM:&lt;/h2&gt;


&lt;h3&gt;schema.yml with Doctrine&lt;/h3&gt;

&lt;pre&gt;
Article:
  columns:
    title:   string(255)
    body:    string(4096)
    user_id: integer(4)
  relations:
    User:
      onDelete: CASCADE
&lt;/pre&gt;


&lt;h3&gt;PHP model with Doctrine&lt;/h3&gt;

&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;php&quot;&gt;public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; setUp&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;hasOne&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'User'&lt;/span&gt;, &lt;a target=&quot;_blank&quot; href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'local'&lt;/span&gt;&amp;nbsp; &amp;nbsp; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'user_id'&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;'foreign'&lt;/span&gt;&amp;nbsp; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;'onDelete'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'CASCADE'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;


&lt;h3&gt;schema.yml with Propel&lt;/h3&gt;

&lt;pre&gt;
    data_id:  { type: integer, primaryKey: true, foreignTable: data, foreignReference: id, onDelete: cascade, onUpdate: cascade }
&lt;/pre&gt;


&lt;h3&gt;schema.xml with Propel&lt;/h3&gt;

&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;foreign&lt;/span&gt;-key &lt;span style=&quot;color: #000066;&quot;&gt;foreignTable&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt; onDelete = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;setnull&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;reference&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;local&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;data_id&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;foreign&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/foreign&lt;/span&gt;-key&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2008/07/10/Foreign-keys-onDelete-for-dummies#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2008/07/10/Foreign-keys-onDelete-for-dummies#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/77</wfw:commentRss>
      </item>
    
  <item>
    <title>Symfony 1.1 is out, and the winner is... 1.2!</title>
    <link>http://www.symforc.com/post/2008/07/01/Symfony-11-is-out-and-the-winner-is-12</link>
    <guid isPermaLink="false">urn:md5:85f53cbd1b862e7ec8d83c276fe0c581</guid>
    <pubDate>Tue, 01 Jul 2008 23:52:00 +0200</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>release</category>
        <category>1.1</category><category>1.2</category><category>deployment</category><category>doctrine</category><category>javascript</category><category>release</category>    
    <description>&lt;p&gt;The longly awaited 1.1 version is finally out after long months of development. After doing this, Fabien started the 1.2 branch, and you can take a look at &lt;a href=&quot;http://trac.symfony-project.com/changeset/10000&quot; hreflang=&quot;fr&quot;&gt;that magnificient revision&lt;/a&gt; which for sure opens a new era of symfony developments.&lt;/p&gt;    &lt;p&gt;A lot of nice new features are greatly awaited in the next version.&lt;/p&gt;


&lt;p&gt;First of all, the admin generator will be completely rewritten, to make a good use of the new form framework. That will for sure open incredible new possibilities and remove the permanent need for hacks to customize your own admin interface (or frontend interface, if you do use admin generation in frontend too). At least, the first one amazed more than one person, and we can be pretty sure that new version will kick asses.&lt;/p&gt;


&lt;p&gt;Some people were complaining about Ruby on Rails having a great advantage over symfony, by their deployment tool Capistrano, while symfony only allow to rsync to one server. Hopefully this won't be true for long anymore. For information, Capistrano allows to create real deployment scripts, like &quot;Disable frontend app on this server, make backups of site and database, synchronize, remotely run tests, clear the cache and enable the frontend app&quot;. That will easify a lot our projects delivery procedures.&lt;/p&gt;


&lt;p&gt;Amongst some other details, the last major point Symfony 1.2 will see is some further decoupling of the technical choices symfony 1.0  gave us, like Propel or Prototype. Prototype and the helpers will still be bundled with symfony, but as a plugin, like Propel is since 1.1. This is very important IMHO, because symfony should never force any technical choice to the teams. But many people complained that helpers was one of the easy and magic things that attract newcomers to symfony. The plugin solution is keeping everyone happy. In the same spirit, symfony 1.2 will bundle the sfDoctrine plugin thanks to Jonathan Wage work to stabilise and manage branches/features.&lt;/p&gt;


&lt;p&gt;And for the short term, the unpublished chapters of the form framework online book are still to come too, along with a symfony 1.1 &quot;First project&quot; tutorial.&lt;/p&gt;


&lt;p&gt;Long life to symfony :-)&lt;/p&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2008/07/01/Symfony-11-is-out-and-the-winner-is-12#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2008/07/01/Symfony-11-is-out-and-the-winner-is-12#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/76</wfw:commentRss>
      </item>
    
  <item>
    <title>HashBin now available in open-source flavor</title>
    <link>http://www.symforc.com/post/2008/03/17/HashBin-now-available-in-open-source-flavor</link>
    <guid isPermaLink="false">urn:md5:247514b555b0056152208ebb017f329f</guid>
    <pubDate>Mon, 17 Mar 2008 23:58:00 +0100</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>sites</category>
        <category>doctrine</category><category>gpl</category><category>hashbin</category><category>opensource</category><category>release</category><category>symfony</category>    
    <description>    &lt;p&gt;Our first violin missed his plane yesterday, so Kwatuor is still not available in the upcoming unusable buggy pre-alpha (that miss all the functionalities anyway).&lt;/p&gt;


&lt;p&gt;But while we're waiting for him to be available, I released HashBin in open-source, so anybody can dive into the code, and help me making it evolve. It still needs many attention, but hey, time is not the most available resource I have, and that's one of the two major reasons to give it to the community. Another one is that there is not so much open source symfony applications, and even less open source doctrine applications. After the doctrine 1.0 feature-freeze announcement, this could be a step to have simple sample applications (I hear little sarcastic laughs in the background...) people could dive in to learn this amazing ORM.&lt;/p&gt;


&lt;p&gt;Well stop talking, here is the code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TRAC web interface: &lt;a href=&quot;http://trac.dakrazy.net/&quot; hreflang=&quot;en&quot;&gt;http://trac.dakrazy.net/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SVN DAV repository: &lt;a href=&quot;http://svn.dakrazy.net/hashbin/trunk/&quot; hreflang=&quot;en&quot;&gt;http://svn.dakrazy.net/hashbin/trunk/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SVN access is read-only for anyone, if you ever want to contribute, I'll be glad to grant you a commit access either on trunk or branch (still have to make up my mind, but at beginning that's not very important). Just ask me on IRC (hartym@freenode).&lt;/p&gt;


&lt;p&gt;What amazing feature will you invent today?&lt;/p&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2008/03/17/HashBin-now-available-in-open-source-flavor#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2008/03/17/HashBin-now-available-in-open-source-flavor#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/71</wfw:commentRss>
      </item>
    
  <item>
    <title>I'd like to hear a Kwatuor play nice symfonic music</title>
    <link>http://www.symforc.com/post/2008/02/26/Id-like-to-hear-a-Kwatuor-play-nice-symfonic-music</link>
    <guid isPermaLink="false">urn:md5:b3bb840e13f98b2a073f5e55b1307bcf</guid>
    <pubDate>Tue, 26 Feb 2008 23:58:00 +0100</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>discussion</category>
        <category>blog</category><category>doctrine</category><category>dotclear</category><category>gpl</category><category>open-source</category><category>project</category><category>symfony</category><category>template</category><category>wordpress</category>    
    <description>    &lt;p&gt;Today's post is a bit special.&lt;/p&gt;


&lt;p&gt;This can be took as a question.&lt;/p&gt;


&lt;p&gt;Or a call to developpers that have specific blogging needs.&lt;/p&gt;


&lt;p&gt;Since quite a moment I used dotclear for blogging. That suit my needs, in some way, but maybe I'm more adaptating my needs to dotclear's capabilities. Maybe you're using wordpress. or any other. And I guess that must be the same for you, thinking for example of integrating one of those all-in-one blogging/cms platforms cleanly in another website, for example, is being more than utopian...&lt;/p&gt;


&lt;p&gt;By clean I mean integrating it without having to duplicate the template. Neither having to use all functionalities if you only need a simple article list somewhere... And without being limited if you need to display the headers of those on another website...&lt;/p&gt;


&lt;p&gt;I'd better not speak of blog networks communicating, or taking content from RSS/XML/anything feed in a flexible way.&lt;/p&gt;


&lt;p&gt;So today I'd like to announce the birth of Kwatuor. Kwatuor is a blog platform project using symfony and doctrine, that will in the near future use doctrine migrations to get content from an existing dotclear/wordpress project, or any other source platform someone has enough need with he'd take the time to write migration classes for.&lt;/p&gt;


&lt;p&gt;Templating system will be different. I'm still hesitating between a generator approach (generated partials from a dynamic skeleton, that all can be customizable) and a real proper template system (but still any part would be customizable). Only major difference with blogging platform would be the total forbidding of DRY-breaks a dotclear-like templating system is doing everyday. And this extends to integrated blogs, in wider projects.&lt;/p&gt;


&lt;p&gt;In fact I started developing it for my own needs, but I think this is typically the kind of project everybody would need someday. Maybe you hate being jailed in your obscure, yet very good, but specific and... even more obscure blog platform.&lt;/p&gt;


&lt;p&gt;So I'm wondering now, if people (you :p) would be interested in this project. If so, I'll make a public SVN/trac next week, so concerned users will be able to give feedback with code in their hands. Would this be usefull to you? Would you contribute to this open-source project? Do you have good (or bad :p) ideas about concepts to take in consideration from the beginning?&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Related links&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.phpdoctrine.org/documentation/manual/trunk/?chapter=migration&quot; hreflang=&quot;en&quot;&gt;Doctrine Migrations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2008/02/26/Id-like-to-hear-a-Kwatuor-play-nice-symfonic-music#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2008/02/26/Id-like-to-hear-a-Kwatuor-play-nice-symfonic-music#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/69</wfw:commentRss>
      </item>
    
  <item>
    <title>Hashbin v3 just went to public beta</title>
    <link>http://www.symforc.com/post/2007/12/24/Hashbin-v3-just-went-to-public-beta</link>
    <guid isPermaLink="false">urn:md5:f6f7e344a7a046feafc461c85861bf94</guid>
    <pubDate>Mon, 24 Dec 2007 06:57:00 +0100</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>release</category>
        <category>annoucement</category><category>beta</category><category>doctrine</category><category>hashbin</category><category>paste</category><category>symfony</category><category>tool</category>    
    <description>    &lt;p&gt;I'm proud to annouce that HashBin v3 is out, using the latest improvements to dkGeshi (old sfGeshi, soon public) and the brand new dkAntispamPlugin, which can give a text a note about its probability of being spam, or junk. If everything goes well with hashbin, and after some required (i guess) tuning to the plugin, it will go opensource to let you take advantage of it.&lt;/p&gt;


&lt;p&gt;For thoose who never used it, HashBin is a free PasteBin service, a collaborative debugging tool allowing developpers to share source code snippets. Hashbin is powered by the Symfony Framework and PHP Doctrine ORM.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://hashbin.com/&quot; hreflang=&quot;en&quot;&gt;Hashbin version 3, beta version&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.symfony-project.org/&quot; hreflang=&quot;en&quot;&gt;Symfony Framework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.phpdoctrine.org/&quot; hreflang=&quot;en&quot;&gt;PHP Doctrine ORM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2007/12/24/Hashbin-v3-just-went-to-public-beta#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2007/12/24/Hashbin-v3-just-went-to-public-beta#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/62</wfw:commentRss>
      </item>
    
  <item>
    <title>Using DBMS functions with sfDoctrine</title>
    <link>http://www.symforc.com/post/2007/10/28/Using-aggregate-functions-with-sfDoctrine</link>
    <guid isPermaLink="false">urn:md5:fc9ef2b2d0bb0c63d95b7e7a5ba34427</guid>
    <pubDate>Tue, 30 Oct 2007 22:11:00 +0100</pubDate>
    <dc:creator>Romain</dc:creator>
        <category>how-to</category>
        <category>aggregate</category><category>database</category><category>doctrine</category><category>MySQL</category><category>portability</category><category>sql</category>    
    <description>&lt;p&gt;I recently had a peek on symfony forum, and seen someone asking &quot;How can I make a SELECT count(*) FROM .... with doctrine?&quot;. An answer to such a question should be pretty obvious as it's of everyday use, but the question seems to have come to life many times as well on IRC than on the forum/mailing list. Here is my two-cents how-to.&lt;/p&gt;    &lt;h2&gt;Using builtin DQL aggregate functions&lt;/h2&gt;


&lt;p&gt;Basically, you can add aggregate functions (functions that operates on a group of records instead of one record, also called GROUP BY functions) to your DQL query the same way you'd do in SQL, provided the fact you're using one of the builtin DQL aggregate functions (COUNT, MAX, MIN, AVG, SUM).&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; = Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'COUNT(t.id) cnt'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Table t'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getFirst&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;a target=&quot;_blank&quot; href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'cnt'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;/code&gt;&lt;/div&gt;


&lt;h2&gt;Using DBMS specific aggregate functions&lt;/h2&gt;


&lt;p&gt;If the function you need is in the list, no need to go further. But some functions are DBMS specific, for example MySQL provides a &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat&quot; hreflang=&quot;en&quot;&gt;GROUP_CONCAT()&lt;/a&gt; function. It would be nonsense for DQL to provide that, as it would not be translatable in some of the other DBMS SQL, but it would also be nonsense to restrict functionalities to the smallest common functionnalities set of every DBMS that Doctrine supports.&lt;/p&gt;


&lt;p&gt;The way to go is to change the &lt;a href=&quot;http://phpdoctrine.net/index.php/documentation/manual?chapter=configuration#general-attributes:portability:portability-mode-constants&quot; hreflang=&quot;en&quot;&gt;portablility level&lt;/a&gt; of doctrine, to match your needs. As the name implies, you're loosing in portability between the different DBMS, but you're gaining specific functionnalities of yours.&lt;/p&gt;


&lt;p&gt;The following code, running in PORTABILITY_ALL mode, will throw a Doctrine_Query_Exception:&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;php&quot;&gt;Doctrine_Manager::&lt;span style=&quot;color: #006600;&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setAttribute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;ATTR_PORTABILITY&lt;/span&gt;, Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;PORTABILITY_ALL&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; = Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'GROUP_CONCAT(t.value) concatedstring'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Table t'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getFirst&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/code&gt;&lt;/div&gt;


&lt;p&gt;Now remove the Doctrine::PORTABILITY_EXPR bit to this attribute, and you will get the correct result (with mySQL):&lt;/p&gt;
&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;php&quot;&gt;Doctrine_Manager::&lt;span style=&quot;color: #006600;&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setAttribute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;ATTR_PORTABILITY&lt;/span&gt;, Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;PORTABILITY_ALL&lt;/span&gt; ^ Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;PORTABILITY_EXPR&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; = Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'GROUP_CONCAT(t.value) concatedstring'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Table t'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getFirst&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;a target=&quot;_blank&quot; href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'concatedstring'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;/code&gt;&lt;/div&gt;



&lt;h2&gt;Extending to other functions&lt;/h2&gt;


&lt;p&gt;Ok aggregate functions are usefull, but other functions can be very handy too, &lt;a href=&quot;http://phpdoctrine.net/index.php/documentation/manual?chapter=dql-doctrine-query-language#functional-expressions:string-functions&quot; hreflang=&quot;en&quot;&gt;string functions&lt;/a&gt; for example. Doctrine manual tells us that builtin DQL string functions are CONCAT, SUBSTRING, TRIM, LOWER, UPPER, LOCATE and LENGTH.&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;php&quot;&gt;Doctrine_Manager::&lt;span style=&quot;color: #006600;&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setAttribute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;ATTR_PORTABILITY&lt;/span&gt;, Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;PORTABILITY_ALL&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$results&lt;/span&gt; = Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'LENGTH(t.value) val_len, t.value'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Test t'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$results&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;a target=&quot;_blank&quot; href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'value'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; . &lt;span style=&quot;color: #ff0000;&quot;&gt;' =&amp;gt; '&lt;/span&gt; .&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'val_len'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; .&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;


&lt;p&gt;This code will display all records' value fields, followed by their character length computed by the DBMS, in PORTABILITY_ALL mode.&lt;/p&gt;


&lt;p&gt;Now let's say you want to use &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_bit-length&quot; hreflang=&quot;en&quot;&gt;BIT_LENGTH&lt;/a&gt; MySQL function...&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;&lt;code class=&quot;php&quot;&gt;Doctrine_Manager::&lt;span style=&quot;color: #006600;&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setAttribute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;ATTR_PORTABILITY&lt;/span&gt;, Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;PORTABILITY_ALL&lt;/span&gt; ^ Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;PORTABILITY_EXPR&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$results&lt;/span&gt; = Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'BIT_LENGTH(t.value) val_len, t.value'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Test t'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$results&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;a target=&quot;_blank&quot; href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'value'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; . &lt;span style=&quot;color: #ff0000;&quot;&gt;' =&amp;gt; '&lt;/span&gt; .&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'val_len'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; .&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;


&lt;p&gt;This is the way to go again.&lt;/p&gt;


&lt;p&gt;No need to say, this extends to every type of functions available in the different DBMS.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2007/10/28/Using-aggregate-functions-with-sfDoctrine#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2007/10/28/Using-aggregate-functions-with-sfDoctrine#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/55</wfw:commentRss>
      </item>
    
</channel>
</rss>