hasMany(Order::className(), array('customer_id' => 'primaryKey'))->orderBy('create_time'); } public static function active($query) { $query->andWhere(array('status' => 1)); } public function afterSave($insert) { ActiveRecordTest::$afterSaveInsert = $insert; ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord; parent::afterSave($insert); } }