f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
206 stars 89 forks source link

Throw error on mapper update/erase if the table has no primary key #285

Closed xfra35 closed 5 years ago

xfra35 commented 5 years ago

I just had a bad experience today with the DB\SQL\Mapper->save() executing an UPDATE on the whole table instead of a single row. I realized that the table had a unique key but no primary key... and the framework did nothing to prevent the massive undesired UPDATE.

Hence this proposal to throw an error on update/erase() if no PK can be found.

KOTRET commented 5 years ago

i welcome this pr, although i can imagine of config-tables with only one row in it, so that this breaks compatibility.

ikkez commented 5 years ago

I'm actually for this change, as I also had a similar adventure once before. If there are edge-cases for 1-row tables, we'll find a solution for it. I could imagine to put this behaviour into a mass-update method, so that you can batch-update all or some records at once.