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

Rodrigo Moraes rodrigo.moraes at gmail.com
Wed Feb 7 21:36:56 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.
>
> Does all that make sense?  Let me know if I'm missing anything.

Just to make it clear, the interface $post->comments->loadPage(2) is
nice; I don't like very much the rows being loaded (page 1) and then
realoded (requested page). I would prefer to build the query myself to
avoid the unnecessary query. :-|

That's why I'm suggesting the possibility to override the related
model options. Then in a subclass I could also do this:

       $options = array(
           'limit'  => $paging,
           'offset' => ((int) $paging * (int) $page) - (int) $paging,
           'cols'   => array('id', 'title'),
       );

       $this->_data[$name] = $this->_model->fetchRelated(
           $name,
           $this->_data[$primary_key],
           $options
       );

And avoid loading whole rows of child models when I just need their
titles; this btw is a performance concern that could be extended to
other Solar_Sql_Model methods. And there's a simple improvement imo.
Instead of:

    $cols = array_keys($this->_table_cols);

...every fetch method could receive an optional extra parameter $cols,
to restrict the selected columns ("I need a varchar, don't load a clob
when it is not needed"):

    $cols = $cols ? $cols : array_keys($this->_table_cols);

...and so we would have:

    fetch($val, $cols = null)
    fetchOne($where = null, $order = null, $cols = null)
    fetchAll($where = null, $order = null, $page = null, $cols = null)
    fetchRelated($name, $spec, $options = null)

It's important enough for me to restrict loaded pages and columns ("I
need an user name for this list, not all his data"), but also I'm just
reporting my concerns; I can't avoid the need to restrict selected
rows and columns in most common cases. Get a better server is a good
idea too ;-), but well, I hope the above is simple and clean enough.

rodrigo


More information about the solar-talk mailing list