Skip to content

feat: Resolution of bug Values of some categories are altered to the …#196

Open
rameenaamir137 wants to merge 3 commits intomainfrom
fix/195-values-altered-after-editing-classification
Open

feat: Resolution of bug Values of some categories are altered to the …#196
rameenaamir137 wants to merge 3 commits intomainfrom
fix/195-values-altered-after-editing-classification

Conversation

@rameenaamir137
Copy link
Copy Markdown
Collaborator

Fix: Empty integer fields saved as 0 instead of NULL
Problem Description
When creating or editing classifications in ReLiS, empty integer fields (such as "Number of citations") were being saved as 0 in the database instead of NULL. This caused issues when editing classifications - fields that were intentionally left empty would show 0 instead of remaining empty.
Root Cause
The form processing logic in relis_app/models/DBConnection_mdl.php was only checking for empty date fields to send as NULL to stored procedures, but was not handling empty int or number fields properly. Empty integer fields were being sent as empty strings ('') which MariaDB/MySQL stored procedures automatically convert to 0.
Solution
Modified the form processing logic to check for empty integer fields and send them as NULL instead of empty strings.
Files Changed
relis_app/models/DBConnection_mdl.php - Modified form processing logic in save_reference_mdl() function
Testing
✅ Create a new classification with empty "Number of citations" field
✅ Save the classification - field should store NULL in database
✅ Edit the classification - field should remain empty instead of showing 0
✅ Verify that non-empty integer fields still work correctly
✅ Verify that other field types (text, date, etc.) are not affected

Screenshots
Screenshot 2025-07-16 at 10 18 35 AM
Screenshot 2025-07-16 at 10 18 45 AM

…default values after editing the classification
@gauranshkumar
Copy link
Copy Markdown
Collaborator

Hello @rameenaamir137, you can update this branch with the current main; it should fix the GitHub Action build issue.

Cheers!

(isset($value['input_type']) && $value['input_type'] == 'date' && empty($val)) ||
(isset($value['field_type']) && in_array($value['field_type'], ['int', 'number']) && empty($val))
) {
return "NULL";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why can't we use return NULL instead of return "NULL" it will be consistent with php null right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants