1

Is it possible to generate that SQL without hacking?

DELETE FROM product WHERE (type=1 AND deleted=1) OR (type=2 AND category=10);
Anıl Özselgin
  • 420
  • 1
  • 4
  • 9

1 Answers1

1

use this sample:

$db->delete(array('(type=1 AND deleted=1) OR (type=2 AND category=10)'));

or if you have a model class for each table so:

$model = new Product();
$model->delete(array('(type=1 AND deleted=1) OR (type=2 AND category=10)'));
Aref Anafgeh
  • 512
  • 1
  • 6
  • 20
  • Still it seems like a hacky solution. – Anıl Özselgin Jan 27 '16 at 14:54
  • Exec also solves my problem. I want to find a proper way. I was trying to find a more structured way like we do in selects. – Anıl Özselgin Jan 28 '16 at 08:40
  • first of all if this solved your problem then you sholud accept my answer..second,this methods create a query in zend db table or zend_db_table_abstract libraries....you can take a look at them to underestand the system – Aref Anafgeh Jan 28 '16 at 09:29
  • Thanks for your answer. But in the question i asked for a solution "without hacking". Maybe I was not clear enough. I was trying to find a solution like andX and orX of doctrine. Please check this solution for doctrine http://stackoverflow.com/questions/9815047/chaining-orx-in-doctrine2-query-builder I'll accept your solution. Thanks for your help. – Anıl Özselgin Jan 29 '16 at 11:38