[Solar-talk] Solar_Sql_Table::setRowClass() / setAllClass()

Rodrigo Moraes rodrigo.moraes at gmail.com
Sat Jan 6 07:22:09 PST 2007


These are some useful simple methods that I've been using for a while
in a class that extends Solar_Sql_Table:

    /**
     *
     * Sets the object class returned by fetch(), fetchNew(), and fetchWhere().
     *
     * @var string $class Class name.
     *
     */
    public function setRowClass($class)
    {
        $this->_row_class = $class;
    }

    /**
     *
     * Sets the object class returned by fetchAll().
     *
     * @var string $class Class name.
     *
     */
    public function setAllClass($class)
    {
        $this->_all_class = $class;
    }

(it could be also useful to add them to Solar_Sql_Table::__get(), but
actually I never used it)

My use case is a model schema that builds a table module *and* also
acts like a row/rowset:

class Tipos_Content_Sql extends Solar_Sql_Rowset
...
    /**
     *
     * Builds a table module object and sets this class for returned results.
     *
     * @param string $class The model class name.
     *
     */
    protected function _setTable()
    {
        $class = get_class($this);

       // Build the table object.
       $this->_table = Solar::factory($this->_config['table_class']);

        // Set the object class returned by fetch(), fetchNew(), and
        // fetchWhere().
        $this->_table->setRowClass($class);

        // Set the object class returned by fetchAll().
        $this->_table->setAllClass($class);
    }

It's an interesting schema in terms of flexibility. :-)

regards,
rodrigo


More information about the solar-talk mailing list