• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detecting Model->delete() query result - how to detect error?

The documentation is very sparse (= non-existent) on Model->delete() method error handling. I found out the hard way that when I do not use soft delete and the actual query fails – with, for instance, MySQL 1451 foreign key constraint –, Model->delete() does not return false, but a BaseResult object. But this BaseResult object does not seem to be very helpful, or at least violates clean code principles.

I looked at $BaseResult->resultID property, which seems to be either boolean true or false. this is confusing already. To further obfuscate its real purpose, the source code phpdoc type hint for resultID suggests that it should be a resource or object. So it might be an indicator of failed query or might not.

Then I looked at connID property, which, if I am not mistaken, is the actual database connection object (mysqli in my case). It eventually contains the last errno/message, but it would not be a good practice to build my app on implementation detail that should be hidden by BaseResult class.

Could not find any other property or method that would contain true/false or error code/message.

Please advise. Thanks in advance.

Messages In This Thread
Detecting Model->delete() query result - how to detect error? - by bivanbi - 06-30-2020, 10:19 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.