I am new to DataMapper ORM in CodeIgniter, here is my question. According to the manual :
Be careful with this method. Without having limited it with where
statements or similar methods it will modify every single row on the
table!Also, this method bypasses validation, and can also operate on in-table foreign keys, so please be aware of the risks.
If the update method bypasses validation, what is the way to update a record validating it before update? A sample code will be appreciated.
DataMapper ORM can’t validate because it can only do that on data that you have fetched first. Using
UPDATElets MySQL modify the fields without checking the eventual PHP validation functions.The solution is first grabbing all the rows you need, and using the
save()function. Then PHP-side validation will be done.http://datamapper.wanwizard.eu/pages/save.html
I am a bit rusty at DataMapper ORM but here’s an example that should explain what you should do: