[Solar-talk] Changes afoot: a new Model class
Rodrigo Moraes
rodrigo.moraes at gmail.com
Wed Feb 7 19:42:29 PST 2007
On 2/8/07, Paul M Jones wrote:
> The thing about this is, because $post->comments is a RecordSet
> object, we can use methods on that object. So, $post->comments-
> >loadPage(2), or something like that, is possible. It already has
> all the information it needs to do the same SELECT as before, just
> with a different LIMIT and OFFSET.
>
> With all that in mind, it seems like RecordSet is the place for that
> kind of behavior. Of course, it would apply to all classes descended
> from RecordSet: voila, no need to subclass RecordSet.
Paul, I was playing with it; I see the restrictions for limit
(count/offset), and this is what I was trying to do:
class Tipos_Sql_Model_Record extends Solar_Sql_Model_Record
{
public function getRelated($name, $paging = null, $page = null)
{
if(!$paging) {
$this->_loadRelated($name);
} else {
$options = ... // set limit - count and offset
$this->_data[$name] = $this->_model->fetchRelated(
$name,
$this->_data[$primary_key],
$options
);
}
return $this->$name;
}
}
Well, the idea I had was to add a third optional parameter to
fetchRelated(), with $options to override the defaults defined in the
relationship.
// get the options for this relationship
$opts = array_merge($this->_related[$name], (array) $options);
Then the options could have definitions for the limit (count/offset).
And, oh, I had to make this:
class Tipos_Model_Nodes extends Tipos_Sql_Model
{
protected function _setup()
{
$this->_stack->add('Tipos_Model_');
...
Because I don't know exactly how to add Tipos_Model_ to the stack. And
by the way, the autoloading is nice. :)
rodrigo
-------------------------------
http://tipos.com.br
More information about the solar-talk
mailing list