@@ -23,13 +23,13 @@ public function loadAll($POST, $skippedRelations = [])
2323 $ shortName = StringHelper::basename (get_class ($ this ));
2424 foreach ($ POST as $ key => $ value ) {
2525 if ($ key != $ shortName && strpos ($ key , '_ ' ) === false ) {
26- /* @var $rel ActiveQuery */
26+ /* @var $AQ ActiveQuery */
2727 /* @var $this ActiveRecord */
2828 /* @var $relObj ActiveRecord */
2929 $ isHasMany = is_array ($ value ) && is_array (current ($ value ));
3030 $ relName = ($ isHasMany ) ? lcfirst (Inflector::pluralize ($ key )) : lcfirst ($ key );
31- $ rel = $ this ->getRelation ($ relName );
32- $ relModelClass = $ rel ->modelClass ;
31+ $ AQ = $ this ->getRelation ($ relName );
32+ $ relModelClass = $ AQ ->modelClass ;
3333 $ relPKAttr = $ relModelClass ::primaryKey ();
3434 $ isManyMany = count ($ relPKAttr ) > 1 ;
3535
@@ -41,7 +41,7 @@ public function loadAll($POST, $skippedRelations = [])
4141 foreach ($ value as $ relPost ) {
4242 if (array_filter ($ relPost )) {
4343 $ condition = [];
44- $ condition [$ this -> primaryKey () [0 ]] = $ this ->primaryKey ;
44+ $ condition [$ relPKAttr [0 ]] = $ this ->primaryKey ;
4545 foreach ($ relPost as $ relAttr => $ relAttrVal ) {
4646 if (in_array ($ relAttr , $ relPKAttr ))
4747 $ condition [$ relAttr ] = $ relAttrVal ;
@@ -349,7 +349,8 @@ public function getAttributesWithRelatedAsPost()
349349 $ shortName = StringHelper::basename (get_class ($ this ));
350350 $ return [$ shortName ] = $ this ->attributes ;
351351 foreach ($ this ->relatedRecords as $ name => $ records ) {
352- if (is_array ($ records ) && is_array (current ($ records ))){
352+ $ AQ = $ this ->getRelation ($ name );
353+ if ($ AQ ->multiple ){
353354 foreach ($ records as $ index => $ record ) {
354355 $ return [$ name ][$ index ] = $ record ->attributes ;
355356 }
@@ -365,7 +366,8 @@ public function getAttributesWithRelated()
365366 {
366367 $ return = $ this ->attributes ;
367368 foreach ($ this ->relatedRecords as $ name => $ records ) {
368- if (is_array ($ records ) && is_array (current ($ records ))){
369+ $ AQ = $ this ->getRelation ($ name );
370+ if ($ AQ ->multiple ){
369371 foreach ($ records as $ index => $ record ) {
370372 $ return [$ name ][$ index ] = $ record ->attributes ;
371373 }
0 commit comments