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

Paul M Jones pmjones at ciaweb.net
Wed Feb 7 17:07:44 PST 2007


On Feb 7, 2007, at 6:57 PM, Rodrigo Moraes wrote:

>> Still, I'm not sure where the business logic goes. I'm assuming it
>> should be put in a subclass of Solar_Sql_Model, but then it's (very
>> strictly speaking, unless using a technique like the one I showed  
>> in my
>> previous email) unavailable in the records themselves (effectively
>> removing alot of the "active" in "active record").
>
> I understand that the business logic is naturally more necessary in a
> per record basis, right? From a table/rowset/row subclasses scheme
> which is what we have in Solar 0.26, we go to a model/record (and
> optionally recordset) subclasses scheme. Business logic go to
> record/recorset. The model only takes care of the model definitions
> and relationships. I'm just guessing and trying to understand.

Hell, I'm guessing half the time myself.  I really do wish that PHP  
had late static binding so we could do the sensible thing and combine  
the table interactions (as class statics) with the row interactions  
(as instance methods) in the same class.


>> Note how they talk back and forth to each other automatically, with
>> lazy-loading of to-many relationships and eager loading of to-one
>> relationships.
>
> Hmm, very very nice. I'm thinking loud that I would love this but in
> many cases I would need to restrict the number of rows returned by the
> child model. :)

I have this in place right now:

     $this->_hasMany('comments', array('limit' => 25, 'order' =>  
'comments.id DESC'));

So you always get the last 25 comments, no offset.  Would that help?

It's not flexible at read-time, though, it's part of the definition  
of the relationship.  More on that in a moment.


> I don't have experience with these kind of models; is
> paging a feature for to-many relationships on Rails or this is / will
> be possible with Solar_Model?

I've been thinking about that, and I really like the idea, but it's  
not possible with Solar_Sql_Model just yet.  The question is, how  
would you implement it?  What would the method-calls look like in  
practice?

Maybe I can add something to RecordSet that reloads based on the page  
number, for $post->comments->loadPage(2) to make a new SELECT and  
reload new comments data.

Actually, that's not a bad idea.  Let me think on it some more.  And,  
of course, happy to take suggestions.



--

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

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

Join the Solar community wiki!  <http://solarphp.org>

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




More information about the solar-talk mailing list