Login | Register
My pages Projects Community openCollabNet

Discussions > dev > propel-1.3.0beta4 patch doSave with autoincrement

propel
Discussion topic

Back to topic list

propel-1.3.0beta4 patch doSave with autoincrement

Reply

Author cyrille heulland <cheulland at gmail dot com>
Full name cyrille heulland <cheulland at gmail dot com>
Date 2008-03-26 09:58:48 PDT
Message Hi ,

I have exclude all autoincrement primary key in buildCriteria function
during generation with the following code of
PHP5ObjectBuilder::a​ddBuildCriteria.

I have done test with patForms and Propel 1.3.0 beta4 and that's working
with perfectly bookstore project.

{{{
protected function addBuildCriteria(&$script)
    {
        $script .= "
    /**
     * Build a Criteria object containing the values of all modified columns
in this object.
     *
     * @return Criteria The Criteria object containing all modified
values.
     */
    public function buildCriteria()
    {
        \$criteria = new
Criteria(".$this-​>getPeerClassname()​."::DATABASE_NAME);
";

        $pks_auto_increment = array();
        if ($this->getTable​()->getIdMethod()​ != IDMethod::NO_ID_METHOD) {

            if (count($pks = $this->getTable(​)->getPrimaryKey(​))) {
                foreach ($pks as $pk) {
                    if ($pk->isAutoIncrement()) {
                        $pks_auto_increment[] = strtolower($pk->getName());
                    }
                }
            }
        }

        foreach ($this->getTable​()->getColumns() as $col) {
            $clo = strtolower($col->getName());
            if(array_search($cl​o,$pks_auto_increme​nt) === false){
            $script .= "
        if (\$this->isColu​mnModified(".$this-​>getColumnConstan​t($col)."))
\$criteria->add​(".$this->getCol​umnConstant($col)."​, \$this->$clo);";
            }
        }
        $script .= "

        return \$criteria;
    }
";
    } // addBuildCriteria()
}}}
Cyrille Heulland
Attachments

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

propel-1.3.0beta4 patch doSave with autoincrement cyrille heulland <cheulland at gmail dot com> cyrille heulland <cheulland at gmail dot com> 2008-03-26 09:58:48 PDT
Messages per page: