Exemple #1
0
 public function getOrders()
 {
     //with用法,先不用all查询
     $orders = $this->hasMany(Order::className(), array('cid' => 'id'))->asArray();
     //->all();
     return $orders;
 }
Exemple #2
0
 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);
 }
Exemple #3
0
 public function getOrder()
 {
     return $this->hasMany(Order::className(), ['user_id' => 'user_id']);
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['profile_id' => 'id']);
 }
Exemple #5
0
 /**
  * @return OrderQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['OrderID' => 'OrderID'])->viaTable('OrderDetails', ['ProductID' => 'ProductID']);
 }
Exemple #6
0
 public function getOrders($id)
 {
     //同样第一个参数指定关联的子表模型类名
     //
     return $this->hasMany(Order::className(), ['id' => 'userid']);
 }
Exemple #7
0
 /**
  * @return OrderQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['ShipVia' => 'ShipperID'])->inverseOf('shipVia');
 }
Exemple #8
0
 /**
  * @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');
 }
Exemple #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrder()
 {
     return $this->hasOne(Order::className(), ['id' => 'orderId']);
 }
Exemple #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['status_fk' => 'status_id']);
 }
Exemple #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['build_fk' => 'build_guide_id']);
 }
Exemple #13
0
 /**
  * @return OrderQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['CustomerID' => 'CustomerID'])->inverseOf('customer');
 }
Exemple #14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['clientNumber' => 'clientNumber']);
 }
Exemple #15
0
 public function getOrders()
 {
     //同样第一个参数指定关联的子表模型类名
     //
     return $this->hasMany(Order::className(), ['addressid' => 'id']);
 }
Exemple #16
0
 public function getOrders()
 {
     $orders = $this->hasMany(Order::className(), ['customer_id' => 'id'])->asArray()->all();
     return $orders;
 }