mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	Fixed yii\db\ActiveRecord::with() unable to use relation defined via attached behavior in case asArray is enabled
				
					
				
			This commit is contained in:
		@ -8,6 +8,7 @@ Yii Framework 2 Change Log
 | 
				
			|||||||
- Bug #14711: Fixed `yii\web\ErrorHandler` displaying exception message in non-debug mode (samdark)
 | 
					- Bug #14711: Fixed `yii\web\ErrorHandler` displaying exception message in non-debug mode (samdark)
 | 
				
			||||||
- Enh #13814: MySQL unique index names can now contain spaces (df2)
 | 
					- Enh #13814: MySQL unique index names can now contain spaces (df2)
 | 
				
			||||||
- Bug #15300: Fixed "Cannot read property 'style' of undefined" error at the error screen (vitorarantes)
 | 
					- Bug #15300: Fixed "Cannot read property 'style' of undefined" error at the error screen (vitorarantes)
 | 
				
			||||||
 | 
					- Bug #15540: Fixed `yii\db\ActiveRecord::with()` unable to use relation defined via attached behavior in case `asArray` is enabled (klimov-paul)
 | 
				
			||||||
- Enh #15426: Added abilitiy to create and drop database views (igravity, vladis84)
 | 
					- Enh #15426: Added abilitiy to create and drop database views (igravity, vladis84)
 | 
				
			||||||
- Enh #10186: Use native `hash_equals` in `yii\base\Security::compareString()` if available, throw exception if non-strings are compared (aotd1, samdark)
 | 
					- Enh #10186: Use native `hash_equals` in `yii\base\Security::compareString()` if available, throw exception if non-strings are compared (aotd1, samdark)
 | 
				
			||||||
- Bug #15122: Fixed `yii\db\Command::getRawSql()` to properly replace expressions (hiscaler, samdark)
 | 
					- Bug #15122: Fixed `yii\db\Command::getRawSql()` to properly replace expressions (hiscaler, samdark)
 | 
				
			||||||
 | 
				
			|||||||
@ -162,7 +162,9 @@ trait ActiveQueryTrait
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $primaryModel = reset($models);
 | 
					        $primaryModel = reset($models);
 | 
				
			||||||
        if (!$primaryModel instanceof ActiveRecordInterface) {
 | 
					        if (!$primaryModel instanceof ActiveRecordInterface) {
 | 
				
			||||||
            $primaryModel = new $this->modelClass();
 | 
					            /* @var $modelClass ActiveRecordInterface */
 | 
				
			||||||
 | 
					            $modelClass = $this->modelClass;
 | 
				
			||||||
 | 
					            $primaryModel = $modelClass::instance();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        $relations = $this->normalizeRelations($primaryModel, $with);
 | 
					        $relations = $this->normalizeRelations($primaryModel, $with);
 | 
				
			||||||
        /* @var $relation ActiveQuery */
 | 
					        /* @var $relation ActiveQuery */
 | 
				
			||||||
 | 
				
			|||||||
@ -1600,5 +1600,13 @@ abstract class ActiveRecordTest extends DatabaseTestCase
 | 
				
			|||||||
        $this->assertInstanceOf(OrderItemWithConstructor::className(), $item);
 | 
					        $this->assertInstanceOf(OrderItemWithConstructor::className(), $item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->assertEquals(1, $item->item_id);
 | 
					        $this->assertEquals(1, $item->item_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // @see https://github.com/yiisoft/yii2/issues/15540
 | 
				
			||||||
 | 
					        $orders = OrderWithConstructor::find()
 | 
				
			||||||
 | 
					            ->with(['customer.profile', 'orderItems'])
 | 
				
			||||||
 | 
					            ->orderBy('id')
 | 
				
			||||||
 | 
					            ->asArray(true)
 | 
				
			||||||
 | 
					            ->all();
 | 
				
			||||||
 | 
					        $this->assertCount(3, $orders);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user