Ticket #93 (new enhancement)

Opened 11 months ago

Solar_Sql_Model::setRelatedParam()

Reported by: rodrigo moraes <rodrigo.moraes@gmail.com> Assigned to: pmjones
Priority: trivial Component: code
Keywords: Solar_Sql_Model Cc:

Description

Hi again,

I added two method to my extended Solar_Sql_Model/Solar_Sql_Model_Record classes that I think are very useful. With them, you can change a model parameter externally. Sometimes it is necessary to change the model relations (paging, order, where, etc) depending on the context, and currently only 'page' can be changed.

Here they are:

Solar_Sql_Model

<?php
    /**
     *
     * Sets a relationship parameter.
     *
     * @param string $name The relationship name.
     *
     * @param string $param The relationship parameter.
     *
     * @param mixed $value The parameter value.
     *
     */
    public function setRelatedParam($name, $param, $value)
    {
        if (empty($this->_related[$name])) {
            // Ignore unrecognized relationship names.
            return false;
        }

        $this->_related[$name][$param] = $value;
    }

Solar_Sql_Model_Record

<?php
    /**
     *
     * Sets a relationship parameter.
     *
     * @param string $name The relationship name.
     *
     * @param string $param The relationship parameter.
     *
     * @param mixed $value The parameter value.
     *
     */
    public function setRelatedParam($name, $param, $value)
    {
        $this->_checkDeleted();
        $this->_model->setRelatedParam($name, $param, $value);
    }

Then, the current Solar_Sql_Model_Record::setRelatedPage() could use be just a wrapper for the method above, instead of doing the checkings itself:

<?php
    /**
     *
     * Sets the page number for a named relation, so that only records from
     * that page are loaded.
     *
     * Resets the loaded records to NULL so that the new records are lazy-
     * loaded on demand.
     *
     * @param string $name The relationship name.
     *
     * @param int $page The page number of records to load.
     *
     * @return void
     *
     */
    public function setRelatedPage($name, $page)
    {
        $this->setRelatedParam($name, 'page', $value);
    }

I hope this makes sense; let me know if you would like to know some use cases.

Attachments


Add/Change #93 (Solar_Sql_Model::setRelatedParam())