Compound database primary key - example doesn't work
Compound database primary key - example doesn't work
json81
Posts: 24Questions: 6Answers: 1
Hi!
I seems to me that the "Compound database primary key"-example doesn't work. I expected the error message to be "This staff member is already busy that day." but instead it shows the default SQL error message: "An SQL error occurred: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '32-2020-03-28' for key 'PRIMARY'"
https://editor.datatables.net/examples/advanced/compoundKey.html
/Anders
This discussion has been closed.
Answers
Yep, the example seems to be broken.
For "lazy people" there is a way to take care of foreseeable SQL errors client side without writing a single line of server side code. This simply replaces the system error message with something more meaningful to the user.
Thanks for pointing that out, and yep, I'm seeing that too. I've raised it internally (DD-1393 for my reference) and we'll report back here when there's an update (it'll probably be on the next web-site build which tends to be around the time of releases).
Cheers,
Colin
I missed the validator for it unfortunately. There should be a global validator for the instance which checks the database to see if there is already a matching item in the database, and if so, then return a nice looking error rather than the SQL one. Its just a case of catching the error earlier.
@json81 - What server-side platform are you using?
Allan
Thanks for all replies. I am using PHP.
Best Regards
Anders
I see this error is still occurring in the online examples, have the php libraries been updated in Editor 2.0 to return a cleaner error message?
Right enough I still haven’t written the validator for it. It isn’t the libraries that need to be updated, but rather a validator used for in the example PHP. I’ve got a bug for this to be fixed in the next patch release now.
Allan
That's the change finally made for this and it will drop in 2.0.2. The compound key example does actually have an edit validator already, but not a create one, which is what I have now added.
Regards,
Allan