Example #1
0
 public function actionQuery()
 {
     //查询用户名为chenhaoran的所有订单
     $user = User::find()->where(['name' => 'chenhaoran'])->one();
     $result = $user->indent;
     //等同于$result = $user->hasMany(Indent::className(),['user_id'=>'id'])->asArray()->all();
     print_r($result);
     //查询拥有价格为23的订单的任一用户
     $indent = Indent::find()->where(['price' => 23])->one();
     $result1 = $indent->user;
     print_r($result1);
     //查询拥有价格为23的订单的所有用户
     $indents = Indent::find()->where(['price' => 123])->all();
     foreach ($indents as $indent) {
         $result2 = $indent->user;
         print_r($result2);
     }
 }
Example #2
0
 public function getIndent()
 {
     //一个user有多个indent,所以用hasMany()
     return $this->hasMany(Indent::className(), ['user_id' => 'id'])->asArray();
 }