All() not returning the expected data

Hi

I’m coming across an odd situation and I’m not sure what I’ve done wrong. my all() call when finding models returns model information, not the data. I can see in the debugger the SQL generated and I can run it directly in TOAD and it works as expected.

Here is the code

$subQuery = new Query();
$subQuery->select(new Expression("1"))
                 ->from('SITE HCPS')
                 ->where(['HCPS.ID' => new Expression('A.ASSMT_PRO_ID')])
                 ->andWhere(['A.DEL_DT' => null])
                 ->andWhere(['HCPS.DEL_DT' => null])
                 ->andWhere(['HCPS.PRIMARY_IND' => 'Y']);

$people = VtAssmt::find()->alias('A')
           ->select([new Expression("DISTINCT(H.FIRST_NAME || ' ' || H.LAST_NAME) AS NAME")])
           ->innerJoinWith('ProH H')
           ->where(['A.DEL_DT' => null])
           ->andWhere(['between', 'TRUNC(A.ENTERED_DT)', 
                  new Expression("TRUNC(TO_DATE('" . $quarterStartDate . "', 'YYYYMMDD'))"),
                  new Expression("TRUNC(TO_DATE('" . $quarterEndDate . "', 'YYYYMMDD'))"),
           ])
           ->andWhere(['not exists', $subQuery])
           ->all();

But what’s returned is:

array (size=1)
  0 => 
    object(app\models\views\VtAssmt)[176]
      private '_attributes' (yii\db\BaseActiveRecord) => 
        array (size=0)
          empty
      private '_oldAttributes' (yii\db\BaseActiveRecord) => 
        array (size=0)
      ...

Not the data that the raw query generates, so what did I do wrong here? Is it that I’m mixing AR and QB?

Update

I just converted the subQuery to an AR record too and I’m finding the same out :thinking:

I figured this out. I needed to select * as it’s trying to reference the innerJoinTable originally

1 Like