use join and where with update

when i use update with join and where

			    $q = Yii::app()->db->createCommand()


				->join('join statement');

				->where('where statement');


i get this error.

Call to a member function join() on a non-object in ....

what is problem?can i use join and where or setjoin and setwhere with update?

The reason you are getting this particular error is because you are ending each line with a semi-colon, you can’t chain method calls this way. Change to:

			    $q = Yii::app()->db->createCommand()


				->join('join statement')

				->where('where statement')


i removed ; but i have that error yet.

i think update, execute sql statement so join and where doesnt work.

Okay I’ve had a look, I can see why you are getting the same error, the update() method returns an integer so you are calling join() against an int which is where the error comes from, try putting the update part of the query last in the chain.

thank you Luke.if i add where and join at first and add update at last,only update query part apply. i checked this with getText().//

i think we can not use ->join() and ->where() with update in query builder although update() have a condition parameter itself but not join.

i dont know if it is a undeveloped case or maybe a newbie issue.

does anyone know any solution to my problem?

Are you on MySQL? If so, you’ll have to stop using the query builder for now due to bug #2788. Try this way instead:

Yii::app()->db->createCommand("UPDATE {{table}} JOIN {{table2}} ON (joincondition) SET `a`=0 WHERE statement")->execute();

thank u but i don’t get a wrong query . i get a error.

Perhaps you can c&p the error message? Are you sure you’ve got an ->execute() at the end?