I have this ActiveQuery that should return an array:
$logData = VisitorLog::find()
->select($reportMetaHash[$selectedType]['select'])
->from("visitor_log v");
foreach($reportMetaHash[$selectedType]['joins'] as $join){
$logData->join($join['type'],$join['table'],$join['on']);
}
$logData->where(['=', 'v.app_id' , $app_id])
->andWhere(['=', 'assorted_id' , $selectedType])
->andWhere(['>=', 'access_time', $app->start_date])
->andWhere('assorted_id IN ('.$selectedType.')')
->groupBy("v.access_log_id, v.content_id")
->orderBy('b.booth_name, u.`first_name`')
->asArray()
->all();
echo '<pre>'; print_r($logData); exit;
This return and ActiveQuery object instead of an expected array.
But when i add the joins without the loop, like below, i get an array, as expected.
$logData = VisitorLog::find()
->select($reportMetaHash[$selectedType]['select'])
->from("visitor_log v")
->join("JOIN", "user u", "u.`app_id`=".$app_id." AND u.id = v.access_log_id AND u.`user_type_id`=8")
->join("JOIN", "document d", "d.doc_id = v.`content_id` AND d.`doctypeId` = 1")
->join("JOIN", "booths b", "b.booth_id = d.booth_id")
->where(['=','v.app_id' , $app_id])
->andWhere(['=', 'assorted_id' , $selectedType])
->andWhere(['>=', 'access_time', $app->start_date])
->andWhere('assorted_id IN ('.$selectedType.')')
->groupBy("v.`access_log_id`, v.content_id")
->orderBy('b.booth_name, u.`first_name`')
->asArray()
->all();
The chaining should work in the loop just as it does without it i think. What am i doing wrong here?
PS: When i run the the same raw query in SQL it returns correct resultset.