YiiMongoDbSuite icon indicating copy to clipboard operation
YiiMongoDbSuite copied to clipboard

EMongoEmbeddedDocument.php aftervalidate errors

Open ghost opened this issue 14 years ago • 1 comments

hi, i dont know this is a bug or feature, but... i have an EMongoDocument with name attribute and it has a location embedded document the location has name attribute too like this: { name: '', location: { name: '' } }

i created a form from this if name and location.name is required too and location.name is empty but name has value in error list i see the name is empty too

i think this function adds extra error message to name attribute:

    /**
     * @since v1.0.8
     */
    public function afterValidate()
    {
        if($this->hasEmbeddedDocuments())
            foreach($this->_embedded as $doc)
            {
                if(!$doc->validate())
                {
                    $this->addErrors($doc->getErrors());
                }
            }
    }

sorry if it is not a real bug, im new yii/mongo user and im new on github

ghost avatar Jun 28 '11 11:06 ghost

This must be a bug. It causes EMongoEmbeddedBehavior not to work properly. I changed to this:

/**
 * @since v1.0.8
 */
public function afterValidate()
{
    if($this->hasEmbeddedDocuments())
        foreach($this->_embedded as $doc)
        {
            if(!$doc->validate())
            {
                $this->addErrors($doc->getErrors());
            }
        }

    parent::afterValidate();
}

luttkens avatar Feb 26 '14 15:02 luttkens