Skip to content

EMongoEmbeddedDocument.php aftervalidate errors #45

Open
uvegpohar opened this Issue Jun 28, 2011 · 1 comment

2 participants

@uvegpohar

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

@luttkens

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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.