public function getOrders() { //with用法,先不用all查询 $orders = $this->hasMany(Order::className(), array('cid' => 'id'))->asArray(); //->all(); return $orders; }
public function actionIndex() { //一个顾客有多少订单 $customer = Customer::find()->where(['id' => 1])->one(); //$orders=$customer->hasMany('\app\models\Order',array('cid'=>'id'))->asArray()->all(); //获取类的全路径 echo Order::className(); //降低耦合:存在的问题是:如果表字段更换,就得从新再修改控制器,所以把这部分业务放在model中处理,以后修改字段,修改model, //$orders=$customer->hasMany(Order::className(),array('cid'=>'id'))->asArray()->all(); //调用model中的方法 //$orders=$customer->getOrder(); //调用类中的魔术方法__get,order属性不存在时,就调用getOrder方法 $orders = $customer->order; var_dump($orders); //查看一个订单属于哪个顾客 $order = Order::find()->where(['id' => 3])->one(); $o = $order->hasOne(Customer::className(), array('id' => 'cid'))->asArray()->one(); var_dump($o); }
public function getOrder() { return $this->hasMany(Order::className(), ['user_id' => 'user_id']); }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['profile_id' => 'id']); }
/** * @return OrderQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['OrderID' => 'OrderID'])->viaTable('OrderDetails', ['ProductID' => 'ProductID']); }
public function getOrders($id) { //同样第一个参数指定关联的子表模型类名 // return $this->hasMany(Order::className(), ['id' => 'userid']); }
/** * @return OrderQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['ShipVia' => 'ShipperID'])->inverseOf('shipVia'); }
/** * @return OrderQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['EmployeeID' => 'EmployeeID'])->inverseOf('employee'); }
/** * @return OrderQuery */ public function getOrder() { return $this->hasOne(Order::className(), ['OrderID' => 'OrderID'])->inverseOf('orderDetails'); }
/** * @return \yii\db\ActiveQuery */ public function getOrder() { return $this->hasOne(Order::className(), ['id' => 'orderId']); }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['status_fk' => 'status_id']); }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['build_fk' => 'build_guide_id']); }
/** * @return OrderQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['CustomerID' => 'CustomerID'])->inverseOf('customer'); }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['clientNumber' => 'clientNumber']); }
public function getOrders() { //同样第一个参数指定关联的子表模型类名 // return $this->hasMany(Order::className(), ['addressid' => 'id']); }
public function getOrders() { $orders = $this->hasMany(Order::className(), ['customer_id' => 'id'])->asArray()->all(); return $orders; }