[Solar-talk] Changes afoot: a new Model class

Andreas Ravnestad andreas.ravnestad at gmail.com
Wed Feb 7 15:12:51 PST 2007


Paul M Jones wrote:
> Hi all,
>
> I've started a new Solar development branch called "model"; you can  
> see it here:
>
>    <http://solarphp.com/svn/branches/model/>
>
> The idea is to start developing something along the lines of the Ruby- 
> on-Rails "ActiveRecord" class.  

This is very interesting, especially since I'm used to working with the 
active record pattern through PEAR::DB_DataObject. Though, it's not 
completely clear to me though how one should work with your 
implementation. Here's a repaste of your code example:

    // object to work with the Nodes model
    $nodes = Solar::factory('Solar_Model_Nodes');

    // get a single record from the model
    $node = $nodes->fetchOne();

This is slightly confusing to me - if I understand this correctly, the 
domain model is $nodes (well, domain model if it has been subclassed and 
extended as to such), and a row (record) with data is represented by 
$node. To insert/update a single row, you call $nodes->save($data).

This implies that to add business logic to the domain model ($nodes) the 
logic would (very often) need a param such as a primary key, and then 
conditionally ask itself for row(s) to work with. Something like this:

    // object to work with blog posts
    $posts = Solar::factory('EnterpriseCompany_Models_Blog_Post');

   // Set new title on a single post, first param is primkey of post to 
alter
   $posts->setTitle(1, 'Solar pwns the competition again');

Where setTitle() is a method that fetches a record with primkey 1, 
changes it, and then calls save() on itself with the altered record data 
as param. Have I got this right?

-AR


More information about the solar-talk mailing list