예제 #1
0
 public function testFindEager()
 {
     $orders = CustomerOrder::find()->with('customer')->all();
     $this->assertEquals(10, count($orders));
     $this->assertTrue($orders[0]->isRelationPopulated('customer'));
     $this->assertTrue($orders[1]->isRelationPopulated('customer'));
     $this->assertTrue($orders[0]->customer instanceof Customer);
     $this->assertEquals((string) $orders[0]->customer->_id, (string) $orders[0]->customer_id);
     $this->assertTrue($orders[1]->customer instanceof Customer);
     $this->assertEquals((string) $orders[1]->customer->_id, (string) $orders[1]->customer_id);
 }
 /**
  * @see https://github.com/yiisoft/yii2/issues/5411
  *
  * @depends testFindEager
  */
 public function testFindEagerHasManyByArrayKey()
 {
     $order = CustomerOrder::find()->where(['number' => 1])->with('items')->one();
     $this->assertNotEmpty($order->items);
 }
예제 #3
0
 public function getOrders()
 {
     return $this->hasMany(CustomerOrder::className(), ['customer_id' => '_id']);
 }