<?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 - propel</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>Complex relations population in propel</title>
    <link>http://www.symforc.com/post/2008/01/31/Complex-relations-population-in-propel</link>
    <guid isPermaLink="false">urn:md5:e7d99dbbc10d08b0818277af69fe8c44</guid>
    <pubDate>Thu, 31 Jan 2008 23:47:00 +0100</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>plugin</category>
        <category>database</category><category>dry</category><category>orm</category><category>performance</category><category>plugin</category><category>propel</category><category>symfony</category>    
    <description>    &lt;p&gt;Since quite a bit, I've been faced with an annoying problem on every projects I use propel on. Propel builders only generates some specific cases selection methods, which consists of pretty ugly copy paste of the same code to populate the objects, and if your needs are not satisfied by the finite little number of propel handled cases, you'll have to either use pure SQL, or write a custom doSelect method. That seems okay at first sight, but it is not. In fact, you're about copypasting the propel generated method, and that's a rude violation of D.R.Y. principle.&lt;/p&gt;


&lt;p&gt;I found no solutions during the two last years, but maybe things will change soon with the new sfPropelImpersonatorPlugin. This plugin is aiming at doing arbitrary object population based on informations provided by propel's introspection methods (DatabaseMap/TableMap/ColumnMap) to link populated objects.&lt;/p&gt;


&lt;p&gt;The plugin is currently in very early stage, but is working pretty well for my needs, and I'm looking forward to know what others are thinking about it.&lt;/p&gt;


&lt;p&gt;Related links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.dakrazy.net/document/sf_propel_impersonator_documentation.html&quot; hreflang=&quot;en&quot;&gt;sfPropelImpersonatorPlugin documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://trac.symfony-project.com/wiki/sfPropelImpersonatorPlugin&quot; hreflang=&quot;en&quot;&gt;sfPropelImpersonatorPlugin README&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://trac.symfony-project.com/browser/plugins/sfPropelImpersonatorPlugin/trunk&quot; hreflang=&quot;php&quot;&gt;Browse the source&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://www.symforc.com/post/2008/01/31/Complex-relations-population-in-propel#comment-form</comments>
      <wfw:comment>http://www.symforc.com/post/2008/01/31/Complex-relations-population-in-propel#comment-form</wfw:comment>
      <wfw:commentRss>http://www.symforc.com/feed/rss2/comments/65</wfw:commentRss>
      </item>
    
  <item>
    <title>Symfony 1.0 is out!</title>
    <link>http://www.symforc.com/post/2007/02/19/Symfony-10-is-out</link>
    <guid isPermaLink="false">urn:md5:e94dbd39cbcfcea567f3df1663e7f890</guid>
    <pubDate>Mon, 19 Feb 2007 08:13:00 +0100</pubDate>
    <dc:creator>Romain Dorgueil</dc:creator>
        <category>release</category>
        <category>doctrine</category><category>MVC</category><category>PHP</category><category>propel</category><category>RAD</category><category>release</category><category>stable</category><category>symfony</category>    
    <description>    &lt;p&gt;Despite the DIGG side effects of which symfony project server suffered because of heavy traffic brought by the well known social bookmarking site's homepage anouncing symfony's first &quot;stable&quot; release, the long awaited 1.0 version is here!&lt;/p&gt;


&lt;p&gt;For thoose who don't know it, Symfony is a MVC (Model-View-Component) PHP5 framework aiming to Rapid Application Development and good codinig practices like the DRY (Don't Repeat Yourself) principle. Their main contributors, french developpers from Sensio Labs Fabien Potencier and François Zaninotto have written a very good documentation book about it, that you can either buy at amazon (for thoose who like holding a real book), or download/read freely on the symfony project website as a PDF file.&lt;/p&gt;


&lt;p&gt;Supported by a large community, you'll find support about symfony in diverse flavour, from the symfony forum to different languages mailing lists, going thru #symfony and #symfony-fr (for french developpers) on Freenode IRC network.&lt;/p&gt;


&lt;p&gt;As the official release note is saying:
&lt;q&gt;At last, the long-awaited 1.0 stable version of symfony is just released. For all those who waited for the &quot;stable&quot; status to dive into symfony, the time has come.&lt;/q&gt;&lt;/p&gt;


&lt;p&gt;Some reference:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.symfony-project.com/&quot; hreflang=&quot;en&quot;&gt;Symfony Project Official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.symfony-forge.com/&quot; hreflang=&quot;en&quot;&gt;Symfony Forge Plugin Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://propel.phpdb.org/&quot; hreflang=&quot;en&quot;&gt;Propel ORM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doctrine.pengus.net/&quot; hreflang=&quot;en&quot;&gt;Doctrine ORM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
      </item>
    
</channel>
</rss>