Skip to content

Commit 5ca9624

Browse files
committed
not validate embedded, if attribute is not safe *
1 parent 19f8ff0 commit 5ca9624

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

AbstractEmbeddedBehavior.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ public function proxy($event)
105105
*/
106106
public function validate()
107107
{
108-
$this->storage->setScenario($this->owner->scenario);
109-
if (!$this->storage->validate()) {
110-
$this->owner->addError($this->attribute, \Yii::t('yii', 'Embedded document in {attribute} must be valid.'));
108+
if ($this->owner->isAttributeSafe($this->fakeAttribute)) {
109+
$this->storage->setScenario($this->owner->scenario);
110+
if (!$this->storage->validate()) {
111+
$this->owner->addError($this->attribute, \Yii::t('yii', 'Embedded document in {attribute} must be valid.'));
112+
}
111113
}
112114
}
113115

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"minimum-stability": "dev",
1717
"require": {
1818
"yiisoft/yii2": "*",
19-
"yiisoft/yii2-mongodb": "*"
19+
"yiisoft/yii2-mongodb": "*",
20+
"yiisoft/yii2-codeception": "*",
21+
"codeception/codeception": "*"
2022
},
2123
"autoload": {
2224
"psr-4": {

tests/_bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

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

12-
require_once(__DIR__ . '/../../../../vendor/autoload.php');
12+
require_once(__DIR__ . '/../vendor/autoload.php');
1313

14-
require_once(__DIR__ . '/../../../../vendor/yiisoft/yii2/Yii.php');
14+
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
1515

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

tests/_config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
],
1515
'mongodb' => [
1616
'class' => 'yii\mongodb\Connection',
17-
'dsn' => 'mongodb://mongo:27017/mongodb_embedded_test',
17+
'dsn' => 'mongodb://localhost:27018/mongodb_embedded_test',
1818
],
1919
],
2020
];

tests/models/SlaveEmbeddedClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class SlaveEmbeddedClass extends EmbeddedDocument
2222
public function rules()
2323
{
2424
return [
25-
['value', 'boolean', 'on' => 'requiredValue'],
2625
['name', 'integer', 'on' => 'requiredName'],
26+
['value', 'boolean', 'on' => 'requiredValue'],
2727
[['name', 'value'], 'safe', 'on'=>'default']
2828
];
2929
}

0 commit comments

Comments
 (0)