Yii Framework Forum: I Think There Is A Flaw In The Code For Createdeletecommand - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I Think There Is A Flaw In The Code For Createdeletecommand Rate Topic: -----

#1 User is offline   lxvi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 13-March 12

Posted 10 February 2013 - 03:56 PM

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....

0

#2 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 10 February 2013 - 05:56 PM

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.../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.

This post has been edited by Coksnuss: 11 February 2013 - 03:34 AM

0

#3 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,084
  • Joined: 16-February 11
  • Location:Japan

Posted 10 February 2013 - 10:33 PM

/* Moved from "General Discussion for Yii 1.1.x" to "Bug Discussions" */
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,084
  • Joined: 16-February 11
  • Location:Japan

Posted 10 February 2013 - 10:59 PM

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.
0

#5 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 11 February 2013 - 05:04 AM

Just for reference: We had a very similar issue regarding UPDATEs with JOINs (see pull request #525).
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#6 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 20 February 2013 - 03:51 AM

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

#7 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 04 March 2013 - 01:39 AM

I added a bug report into the issue tracker.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users