<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Dev411 Blog: Category activerecord</title>
    <link>http://www.dev411.com/blog/tag/activerecord</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>John Wang on Technology</description>
    <item>
      <title>Database Abstraction - code vs infrastructure</title>
      <description>&lt;p&gt;I've worked on a number of database-driven projects and no matter how much people want database abstraction, it was always difficult to code and maintain. I was recently reminded of this when I read this &lt;a href="http://www.drupal4hu.com/node/64" title="My stance on database abstraction"&gt;Drupal article on dropping PostgreSQL support&lt;/a&gt;. Not only can it be difficult to maintain support for multiple databases, but it may be difficult to find developers.&lt;/p&gt;

&lt;p&gt;One solution of modern programming is to move database abstraction from the code to the infrastructure using a ORM (Object-Relational Mapper) or Data Mapper. A ORM and Data Mapper abstracts the database for you so you no longer have to do tie db abstraction to each app. Not only does it let you code once for multiple databases it lets your users migrate their data from one database to another. This blog runs Typo which is based on Ruby on Rails and ActiveRecord. I've been contemplating migrating Typo from MySQL to PostgreSQL and I've been told that it would be as simple as exporting the data with YAML, updating the database.yml file and importing the data. I haven't gotten around to doing it yet but it is a powerful idea. ActiveRecord is a data mapper and isn't as flexible as a full blown ORM but it gets the job done for the most part. For a full-blown ORM, I think of Perl's DBIx::Class which provides a full OO interface to the RDBMS allowing you to code just once for multiple DBs without limiting you when you want to use some esoteric database-specific SQL. DBIx::Class is often used with the Catalyst Framework but is also used by itself.&lt;/p&gt;

&lt;p&gt;There are PHP frameworks out there like Symfony and Cake but do any of them have stand-alone ORMs? If so, could Drupal move to something like that and solve their maintainership problems once and for all? Drupal is part of the &lt;a href="http://gophp5.org"&gt;Go PHP5&lt;/a&gt; effort so there should be no issue using PHP 5 OO. Something to think about for the Drupal folks if a PHP ORM is available.&lt;/p&gt;

</description>
      <pubDate>Tue, 04 Sep 2007 23:38:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:fd57e1bd-e67a-47e8-96e7-2cffbf7b196a</guid>
      <author>John Wang</author>
      <link>http://www.dev411.com/blog/2007/09/04/database-abstraction-code-vs-infrastructure</link>
      <category>postgresql</category>
      <category>catalyst</category>
      <category>activerecord</category>
      <category>perl</category>
      <category>mysql</category>
      <category>typo</category>
      <category>php</category>
    </item>
    <item>
      <title>ActiveRecord - Achilles Heel of Ruby on Rails?</title>
      <description>&lt;p&gt;IMO, one of the major limitations of Ruby on Rails compared to other frameworks is its ORM, ActiveRecord. ActiveRecord is a fairly early ORM (object-relational mapper) that has made some questionable design decisions and doesn't support some very basic relational database concepts. These issues have been &lt;a href="http://discuss.joelonsoftware.com/default.asp?joel.3.309321.3"&gt;discussed on Joel on Software&lt;/a&gt; and elsewhere. Here are some limitations I wish were fixed:&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;&lt;strong&gt;No Foreign Key Support:&lt;/strong&gt; Although RoR lets you define has_many relationships, it makes no effort to create foreign key constraints in the underlying database to ensure relational integrity.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;No Multi-column Primary Key Support:&lt;/strong&gt; Multi-column primary keys are a staple of relational database schema definition. Unfortunately, &lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/140320"&gt;DDH had a pretty simple response&lt;/a&gt;:
&lt;br /&gt;&lt;br /&gt;
&lt;em&gt;&amp;gt; Is there a way to set an ActiveRecord object to point to a table&lt;br /&gt;&amp;gt; with a multi-column primary key?
&lt;br /&gt;&lt;br /&gt;
Not really, no. Active Record was designed for a single column primary key and that assumption runs pretty deep. AR is not a Data Mapper, so you have to be within a reasonable vicinity of its
assumptions to enjoy it.&lt;br /&gt;- David Heinemeier Hansson&lt;/em&gt;&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;As DHH says in his multi-col PK response, you need to be close to ActiveRecord's assumptions, it doesn't cater to your situation. ActiveRecord is nice for many simpler situations but if you want relational integrity and/or have complex relationships, it seems like it may not be the best tool for the job. Other ORMs such as the Perl-based &lt;a href="http://search.cpan.org/~jrobinson/DBIx-Class-0.06003/lib/DBIx/Class.pm"&gt;DBIx::Class&lt;/a&gt; (often used with the &lt;a href="http://www.catalystframework.org"&gt;Catalyst framework&lt;/a&gt;) can handle these issues and many more. According to the 37Signals blog entry &lt;a href="http://www.37signals.com/svn/archives2/growing_in_vs_growing_out.php"&gt;Growing in vs. growing out&lt;/a&gt;, they prefer people to grow out of their applications. I'm curious if they also want people to grow out of ActiveRecord?&lt;/p&gt;</description>
      <pubDate>Sun, 04 Jun 2006 11:12:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:a2217cbb03931530e0c28989c859cc6e</guid>
      <author>John Wang</author>
      <link>http://www.dev411.com/blog/2006/06/04/activerecord-achilles-heel-of-ruby-on-rails</link>
      <category>activerecord</category>
      <category>orm</category>
      <category>rails</category>
    </item>
  </channel>
</rss>
