diff --git a/docs/using-di.md b/docs/using-di.md index f1f2891b0..8837c9447 100644 --- a/docs/using-di.md +++ b/docs/using-di.md @@ -84,11 +84,6 @@ final class User extends ActiveRecord { $this->factory = $factory; } - - public function getMyService(): MyService - { - return $this->myService; - } } ``` diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 490d7bdf3..ca9e246df 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -1032,6 +1032,19 @@ public function testWithFactoryInstanceRelation(): void $this->assertInstanceOf(CustomerWithFactory::class, $order->getCustomerWithFactoryInstance()); } + public function testWithFactoryRelationWithoutFactory(): void + { + $this->checkFixture($this->db(), 'order'); + + $factory = $this->createFactory(); + + $orderQuery = new ActiveQuery($factory->create(OrderWithFactory::class)->withFactory($factory)); + $order = $orderQuery->findOne(2); + + $this->assertInstanceOf(OrderWithFactory::class, $order); + $this->assertInstanceOf(Customer::class, $order->getCustomer()); + } + public function testWithFactoryLazyRelation(): void { $this->checkFixture($this->db(), 'order');