Skip to content

Commit

Permalink
not validate embedded, if attribute is not safe *
Browse files Browse the repository at this point in the history
  • Loading branch information
serieznyi committed Jul 15, 2015
1 parent 19f8ff0 commit 5ca9624
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions AbstractEmbeddedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ public function proxy($event)
*/
public function validate()
{
$this->storage->setScenario($this->owner->scenario);
if (!$this->storage->validate()) {
$this->owner->addError($this->attribute, \Yii::t('yii', 'Embedded document in {attribute} must be valid.'));
if ($this->owner->isAttributeSafe($this->fakeAttribute)) {
$this->storage->setScenario($this->owner->scenario);
if (!$this->storage->validate()) {
$this->owner->addError($this->attribute, \Yii::t('yii', 'Embedded document in {attribute} must be valid.'));
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"minimum-stability": "dev",
"require": {
"yiisoft/yii2": "*",
"yiisoft/yii2-mongodb": "*"
"yiisoft/yii2-mongodb": "*",
"yiisoft/yii2-codeception": "*",
"codeception/codeception": "*"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

defined('YII_ENV') or define('YII_ENV', 'test');

require_once(__DIR__ . '/../../../../vendor/autoload.php');
require_once(__DIR__ . '/../vendor/autoload.php');

require_once(__DIR__ . '/../../../../vendor/yiisoft/yii2/Yii.php');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require('_config.php');

Expand Down
2 changes: 1 addition & 1 deletion tests/_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
'mongodb' => [
'class' => 'yii\mongodb\Connection',
'dsn' => 'mongodb://mongo:27017/mongodb_embedded_test',
'dsn' => 'mongodb://localhost:27018/mongodb_embedded_test',
],
],
];
2 changes: 1 addition & 1 deletion tests/models/SlaveEmbeddedClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SlaveEmbeddedClass extends EmbeddedDocument
public function rules()
{
return [
['value', 'boolean', 'on' => 'requiredValue'],
['name', 'integer', 'on' => 'requiredName'],
['value', 'boolean', 'on' => 'requiredValue'],
[['name', 'value'], 'safe', 'on'=>'default']
];
}
Expand Down

0 comments on commit 5ca9624

Please # to comment.