I need to construct a complicated query running against a main table and several dependent tables. I’m using it like this:
$criteria = new CDbCriteria; $criteria->with = array('product', 'shop', 'address', 'unit');
The complicated part of the query is coded as SQL statement added by means of:
$criteria->join = 'join (SELECT...
The problem araises from the fact that when Yii builds resulting query it uses my join first and then appends its own LEFT OUTER JOIN for each dependent table. This leads to a SQL syntax error due to the complexity of the custom statement passed though $criteria->join. When I change manually the order of joins in the automatically generated query, it runs smoothly. So the question is how can I ensure that Yii will change the order in which it assembles data from
join properties? I need my custom join to be the latest join in the query, and automatically generated LEFT OUTER JOINs to go before it.
Thanks in advance.