spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Customize SQL integrity constrains #239

Closed manelj closed 6 years ago

manelj commented 7 years ago

How can i catch and customize spot orm SQL execution integrity violations or any other sql error?

nebulousGirl commented 7 years ago

With a try/catch or some kind of custom error handler, depends on what you want to achieve.

FlipEverything commented 7 years ago

+1, you can do something like this:

// untested piece of code
$mapper = $spot->mapper('Entity');
try {
  $mapper->update($entity);
} catch (\Spot\Exception $spotException) {
  if (strpos($spotException->getMessage(), 'constraint violation') != false) {
    $response = new Forbidden;
  }
}
FlipEverything commented 6 years ago

Closing this issue, because of the inactivity. Feel free to reopen this if you have more questions regarding this subject.