fix: ajustar el manejo de valores por defecto para campos de fecha y datetime#7
fix: ajustar el manejo de valores por defecto para campos de fecha y datetime#7daniel89fg wants to merge 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue with default value handling for date and datetime fields in the model's clear() method. When adding a NOT NULL date column without providing a default value, the system was previously auto-filling with values from 01-01-1970 (Unix epoch). The fix assumes that date and datetime columns should never have default values and always calls Tools::date() and Tools::dateTime() without parameters to set them to the current date/time.
Key changes:
- Modified the
clear()method inModelClass.phpto ignore the$field['default']parameter for date and datetime fields - Both date and datetime fields now always use the current date/time when clearing a model
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'date' => Tools::date(), // asumimos que el campo fecha nunca tendrá valor por defecto | ||
| 'datetime', 'timestamp' => Tools::dateTime(), // asumimos que el campo datetime nunca tendrá valor por defecto |
There was a problem hiding this comment.
The assumption that date/datetime fields never have default values may not hold true for all use cases. Some fields might legitimately need a specific default date (e.g., a system start date, or a far-future date for 'never expires' scenarios). This change breaks backward compatibility if any models rely on database-defined default values for date fields. Consider checking if $field['default'] is empty/null before falling back to the current date, allowing models with explicitly defined defaults to continue working: 'date' => empty($field['default']) ? Tools::date() : Tools::date($field['default'])
| 'date' => Tools::date(), // asumimos que el campo fecha nunca tendrá valor por defecto | |
| 'datetime', 'timestamp' => Tools::dateTime(), // asumimos que el campo datetime nunca tendrá valor por defecto | |
| 'date' => empty($field['default']) ? Tools::date() : Tools::date($field['default']), | |
| 'datetime', 'timestamp' => empty($field['default']) ? Tools::dateTime() : Tools::dateTime($field['default']), |
Cuando se añade una columna de tipo fecha y esa columna es not null, si no se rellena el clear del modelo puede rellenarse con valores del 01-01-1970 de forma automática, de este modo corregimos ese problema desde el core, asumiendo que las columnas de tipo fecha no tienen un valor por defecto.
¿Cómo has probado los cambios?
Toda modificación debe haber sido mínimamente probada. Marca o describe las pruebas que has realizado:
How has the changes been tested? (english)
Any modification must have been tested minimally. Mark or describe the tests you have performed:
Ayuda
Aquí tienes algunos enlaces de ayuda:
Help (english)
Here are some help links: