[Solar-talk] The new model class discussion, some questions

Paul M Jones pmjones at ciaweb.net
Sun Feb 18 20:11:47 PST 2007


On Feb 18, 2007, at 6:50 PM, Rodrigo Moraes wrote:

> On 2/18/07, Andreas Ravnestad wrote:
>> It looks similar, but those two pieces of code are doing two very
>> different operations (yikes again). The doctrine example returns
>> instances of User. A User is a model whose instance maps directly  
>> to one
>> record, and is extended from Doctrine_Record. The solar example  
>> returns
>> instances of who-knows-what. It might be   
>> Tipos_Sql_Model_Record_Blog.
>> Or Solar_Sql_Model_Record. Who could possibly tell without peeking at
>> the class stack? But the *model* is still Solar_Model_Users  
>> ($users and
>> $user are different types) - and this is where my active record alarm
>> bell (tm) goes ringing.
>
> * who-knows-what = a instance of Solar_Sql_Model_Record ;)

Exactly right.  Alternatively, if you have defined your own record  
class for the model, it will return that.  Solar_Sql_Model_Record is  
the all-purpose fallback that should serve most purposes most of the  
time.


> The main difference as I see is that in DB_DataObject & Doctrine (and
> maybe Rails?) is that you have a record that is the same class of the
> "model",  and it wraps the table. Solar has a model/table that returns
> a record which wraps the model/table.

Yeah, that seems pretty close.  The only point I'd make is that the  
record does not wrap the table/model; instead, it carries with it a  
reference back to the model it came from, so it can use the methods  
from that model for insert/update/validate/etc.


> Yeah, this confuses me and perhaps makes no sense. I also don't know
> what this implies.

Sorry, not trying to confuse.  To reiterate, I think the fact that  
Rails uses the name "ActiveRecord" for something that is only partly  
a formal ActiveRecord has made it too easy to get confused about what  
an ActiveRecord is and should behave like.  :-(


--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.   <http://solarphp.com>

Savant: The simple, elegant, and powerful solution for
templates in PHP.   <http://phpsavant.com>




More information about the solar-talk mailing list