Yii Clistview Search With Subqueries

I am using a CListView to display my data on a page. I have a textbox for searching keywords in the query.

In my query where I build my CActiveDataProvider I have some subqueries. For Example:




$criteria = new CDbCriteria;

$criteria->select = array('

    Lessons.id,

    Lessons.name,

    (SELECT

        COALESCE(CONCAT(u.first_name, " ", u.last_name), last_name, first_name)

    FROM

        users AS u

    WHERE

        u.user_token = Lessons.instructor_id

    ) as instructor_name

');



My model for the above query does have a class variable called $instructor_name.

When I enter data into the textbox I then run this piece of code to join another table for searching.




if ( !empty($query) ) {

    $criteria->with = array('packages');

    $criteria->compare( 'packages.contents', $query, true);

    $criteria->together = true;

}



The results when running a search query do not return the instructor_name data from the subquery. What I seem to find is when I add a value to the with part of the search criteria. e.g. $criteria->with = array(‘packages’); My SQL query that runs does not factor in the original select value. Thus erasing the subquery to use Yii defaults

Any ideas on what is happening here causing my subquery data from loading? Thank you in advance.

Why cant you use AR relations instead of that subquery?