File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 11Yii LinkMany Change Log
22=======================
33
4+ 1.1.4 Under development
5+ -----------------------
6+
7+ - Avoid validating many-to-many relationships by default
8+
491.1.3 Sep 14, 2022
510------------------
611
Original file line number Diff line number Diff line change @@ -119,7 +119,11 @@ public function afterValidate()
119119 foreach ($ this ->relations as $ definition ) {
120120 $ relationName = $ definition ->name ;
121121
122- if (!$ definition ->validate ) {
122+ $ relation = $ this ->owner ->getRelation ($ relationName );
123+
124+ $ validate = $ definition ->validate === null ? !$ relation ->via : $ definition ->validate ;
125+
126+ if (!$ validate ) {
123127 continue ;
124128 }
125129
@@ -131,7 +135,7 @@ public function afterValidate()
131135 }
132136
133137 foreach ($ models as $ i => $ model ) {
134- if (!$ model ->validate ()) {
138+ if (!$ relation -> via && ! $ model ->validate ()) {
135139 $ attribute = $ relationName . "[ $ i] " ;
136140 $ this ->addError ($ model , $ attribute );
137141 }
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class RelationDefinition extends BaseObject
1919 /**
2020 * @var string whether the relation validation is required.
2121 */
22- public $ validate = true ;
22+ public $ validate = null ;
2323
2424 /**
2525 * @var boolean whether to delete the pivot model or table row on unlink.
You can’t perform that action at this time.
0 commit comments