如何在Yii2活动记录中获取关于关系的DISTINCT行

问题描述 投票:0回答:2

我有一个如下的AieDetail模型:

  class AieDetail extends \yii\db\ActiveRecord
  {
      public function getDepts()
      {
          return $this->hasOne(Department::className(), ['DEPT_CODE' => 'DEPT_CODE']);
      }
  }

我有此查询,我想使用它在Department表中选择不同的COL_ABBREV列

  $aie_detail = AieDetail::find()->alias('AD')
                        ->select(['DEPT.COL_ABBREV'])
                        ->joinWith(['depts DEPT'])
                        ->where(['not',['DEPT.COL_ABBREV' => ['CA']]])
                        ->distinct()
                        ->all();
    return $aie_detail;

$ aie_detail]的值是一个查询,而不是数据数组。什么是获取行的正确方法?

我有一个AieDetail模型,如下所示:类AieDetail扩展了\ yii \ db \ ActiveRecord {公共函数getDepts(){返回$ this-> hasOne(Department :: className(),['DEPT_CODE'= ...

php yii2 yii2-active-records
2个回答
0
投票
  $aie_detail = AieDetail::find()
                        ->select([Department::tableName() . '.COL_ABBREV'])
                        ->joinWith('depts')
                        ->where([
                          '!=',
                          Department::tableName() . '.COL_ABBREV',
                         'CA'
                        ])
                        ->distinct()
                        ->asArray()
                        ->all();

-1
投票
$aie_detail = AieDetail::find()->alias('AD')
    ->select('Department.COL_ABBREV')
    ->joinWith(['depts'])
    ->where(['not','Department.COL_ABBREV', 'CA'])
    ->distinct()
    ->all();
© www.soinside.com 2019 - 2024. All rights reserved.