Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

EMongoEmbeddedDocument.php aftervalidate errors #45

Open
ghost opened this issue Jun 28, 2011 · 1 comment
Open

EMongoEmbeddedDocument.php aftervalidate errors #45

ghost opened this issue Jun 28, 2011 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 28, 2011

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
Copy link

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant