Reputation: 1696
I am using Yii CActiveRecord A ->with('B')->findAll() method where one of hte column is common with A and B and this column is also a part of the condition.
Now the problem is that while executing it, I get the SQL error because mySQL does not know if i want to refer to A.column or B.column. I viewed the executed query and it seems yii names table as 't' while executing the query, so i appended the 't'.columnname in the condition and everything worked fine.
My question is if this kind of code is appropriate where i am using the condition as
'CURDATE( ) <= date
AND t
.removed
= :removed AND ispublic
= 1 AND isopen
= 1'
while i do not refer what 't' is in the query. Yii renames the table on its own. Please let me know if this seems to be a fine coding practice or if there is a better way to do it.
thanks.
Upvotes: 0
Views: 587
Reputation: 3950
When you are not using "with()", you can write your condition without appending alias "t" with the column name but when you use "with()" to find data of relations you need to add the alias "t" with base model condition. If their is no common column with relations than you can avoid alias to the base model.
Yii defaults add alias to the base model "t" so you should use "t" with the column names of the base model.
Upvotes: 1