phiras
(Phiras)
February 20, 2010, 12:00am
1
Hi,
I have to find some records in a model with its relations. one of its relations is the same table itself. now when I do the following :
$model = Account::model()->with('profile.comments.account')->find('name=:name', array(':name'=>$name));
The constructed SQL query fail because of the ambiguity of the given condition.
WHERE (name=:name)
I could solve my problem by adding the t
before my column name. but I believe that AR should add the alias of the table in the whee clause.
Am I right ?
phpdevmd
(Phpdevmd)
February 20, 2010, 11:10am
2
I found the same flow in Yii-1.1 branch.
In Yii-1.0 you would need to use
tbl_name
.name
=:name
in Yii-1.1 this:
t
.name
=:name
If you look in yii demos/blog it also uses t
.field
instead of tbl_name
.field
If you are going to search by some field in ->with() array - this is where you’ll need to apply alias to table name.
Cheers
phiras
(Phiras)
February 20, 2010, 2:21pm
3
umm, It doesn’t make any sense to include my table name in my code! what I changed the name of my table in the future, or maybe Yii will replace t
with something else!