示例#1
0
 public function testAfterFindGet()
 {
     /* @var $customerClass BaseActiveRecord */
     $customerClass = $this->getCustomerClass();
     $afterFindCalls = [];
     Event::on(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND, function ($event) use(&$afterFindCalls) {
         /* @var $ar BaseActiveRecord */
         $ar = $event->sender;
         $afterFindCalls[] = [get_class($ar), $ar->getIsNewRecord(), $ar->getPrimaryKey(), $ar->isRelationPopulated('orders')];
     });
     $customer = Customer::get(1);
     $this->assertNotNull($customer);
     $this->assertEquals([[$customerClass, false, 1, false]], $afterFindCalls);
     $afterFindCalls = [];
     $customer = Customer::mget([1, 2]);
     $this->assertNotNull($customer);
     $this->assertEquals([[$customerClass, false, 1, false], [$customerClass, false, 2, false]], $afterFindCalls);
     $afterFindCalls = [];
     Event::off(BaseActiveRecord::className(), BaseActiveRecord::EVENT_AFTER_FIND);
 }
示例#2
0
文件: Order.php 项目: sciurodont/yii2
 public function getCustomer()
 {
     return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
 }