I Think There Is A Flaw In The Code For Createdeletecommand

In the code for createDeleteCommand I see that there is a string literal that reads "DELETE FROM"

However, when I’m in the mysql command line prompt and type something like


delete from team left join user on( team.id=user.team_id ) where user.team_id is null

I get a syntax error, and so I believe that there will be grief were I to try


Team::model()->deleteAll( array( 'join'=>'left join user on team.id=user.team_id', 'condition'=>'user.team_id is null' ));

even though one would think that should be legal.

I believe that the code in createDeleteCommand needs to be changed to also include the table name between the DELETE and the FROM, so that the resulting SQL will read


DELETE team FROM team left join....

I am not too sure what you are trying to achieve but "DELETE team FROM" is not a valid SQL query (See MySQL Documentation http://dev.mysql.com/doc/refman/5.1/de/delete.html)

Maybe "DELETE FROM user WHERE team_id IS NULL" is what you are searching for?

// Edit: Oh, seems that i was wrong… sorry for that.

[color="#006400"]/* Moved from "General Discussion for Yii 1.1.x" to "Bug Discussions" */[/color]

According to the MySQL reference, the following is a valid SQL syntax.




DELETE table_a FROM table_a JOIN table_b ON table_a.id = table_b.fk WHERE table_b.foo = 'bar';



And this seems quite handy in some situations.

But, I’m not sure if other DBMS support DELETE using JOIN by the same syntax, and if we can implement this in CDbCommandBuilder::createDeleteCommand or not.

[EDIT]

I forgot to say that I agree with lxvi.

The source code tells that it apparently wants to support JOIN in DELETE. But it will result in error.

Just for reference: We had a very similar issue regarding UPDATEs with JOINs (see pull request #525).

I have this issue too. Did some one add the bug report already? I can not find it in yii issue tracker.

I added a bug report into the issue tracker.