Model deleting error

Why sometimes I get an error ```log SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 ``` on calling $model->delete(); ?

Where $model is a valid instance of Model.

The reason of this error: Model hasn't primary key. Can I use Models without it?



83.4k

A model cannot be deleted without a primary key, the SQL is dynamically generated to delete exactly the record you have in memory, without a primary key there is no certainty that the deleted record is the same that is currently in memory.

If this is not real, I think that Phalcon should throw an Exception with short description, because MySQL syntax error is not so informative.

Also, PhpMyAdmin removes that entries by query "DELETE FROM table WHERE field1 = '...' AND field2 = '...' AND field3 = '...' LIMIT 0,1"



83.4k

I agree, I'm going to add an exception for that 1.2

Cool :-) Thanks.