Quantcast
Channel: ASPRunner forums
Viewing all articles
Browse latest Browse all 2586

Handling Constraints

$
0
0
Say you have a table Categories and a table things. Each record in Categories can have many child records in Things, 1:n relation between Categories and Things, the relation is from Categories-Primary-Key to a foreign-key field in Things.
I've setup this structure in mySQL and set a constraint for relational integrity in mySQL, so that you cannot delete a record in Categories when there are still related records in Things.

Now I've read that you can handle this with Events in phpr, by issuing a sql query in the before delete event to see if there are any related records, and if yes, to deny the delete.
For my case I need to ensure this also at the database level with the above mentioned constraints.

Here comes the question: is it possible to just work with the errors that result from the constraints and omit having to write the Event code (see above)?
So: let the db-engine do the constraint check and if there's a violation, catch the error in phpr and move on from there?
In my test I just get a generic php error page with the constraint in place (and no event code yet).

I guess I'll have to do both: write the constraints (as a last line of defense) and still do the pre-checks via events.

Thanks!

Viewing all articles
Browse latest Browse all 2586

Trending Articles