Yii 1.0 > 1.1 upgrade causes strange SQL queries

Hello,

I am upgrading Yii from version 1.0 to 1.1.5 but I’m getting unexpected results with my SQL queries.

In some of my models I am using the defaultScope() method to specify a condition that should be applied to the main query but in Yii 1.1.5 this behavior has changed and the defaultScope() conditions are applied to the JOIN clause and not the main query’s WHERE clause like they were in Yii 1.0.

In other words, my query’s now look like this:

SELECT …

FROM …

*AND …

LEFT OUTER JOIN …

LEFT OUTER JOIN …

LEFT OUTER JOIN …

*AND …

WHERE …

ORDER BY …

LIMIT …

And I need the AND’s (*) to be after the WHERE clause.

I’ve been trying all day to fix this but I can’t find a solution. Any ideas??

Thanks,

Johan

I don’t suppose this will change much, but in your situation I would try to do 1.0 --> 1.1 upgrade to see if everything is fine and only then to go further with 1.1 --> 1.1.5 upgrade. Or maybe even with smaller steps, to precisely separate, which version is causing your problems.

Have you read an article in Definitive Guide about migrating from 1.0 to 1.1?

Thank you for your reply!

It seems the problem I’m experiencing is because of the following change introduced in version 1.1.3:

- The ‘condition’ declared in the scopes of the related AR classes will now be put in the ‘ON’ clause of the JOIN statement when performing relational AR queries.

I’m not sure how to fix this without having to rewrite my SQL queries though. They should have added some sort of flag to keep compability.