tbar0970 / jethro-pmm

Jethro Pastoral Ministry Manager
GNU General Public License v3.0
35 stars 25 forks source link

DB error when trying to save several services for same date. #78

Closed tbar0970 closed 1 year ago

tbar0970 commented 9 years ago

Steps to reproduce:

  1. Go to services > Service program
  2. Edit the service program for some congregations, for a date range which doesn't have any services saved yet
  3. The table has editable date fields down the left. Adjust one of these dates so it's the same as another row. Enter some service details for both rows.
  4. Save.
  5. DB error results: Duplicate value for "datecong".

Expected behaviour: Before form submission, Jethro checks for duplicate dates and blocks submission. (Coudl also add better server-side detection, but client-side detection will make sure all the rest of the data in the form is not lost).

edwhiting commented 8 years ago

Do you want to make use of MySQL's ON DUPLICATE KEY UPDATE feature at the database level so that it doesn't throw an exception when this happens? http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html This wouldn't preclude adding some code on the client side to warn the user and possibly prevent the user from saving the form.

tbar0970 commented 8 years ago

A silent overwrite isn't the behaviour we want, so ON DUPLICATE KEY UPDATE isn't the solution we need.

To catch it server side, we could override db_object::readyToCreate() in the service class, and add a query that checks for existing services for that congregation and date. BUT that would necessitate an extra query for each service saved (sometimes there are a lot saved at once). So given that the existing behaviour is blocking the save correctly (albeit noisily) I think just adding a client-side check would be the best solution right now.