I have an Entity.
My\Bundle\Entity\Service:
type: entity
table: SERVICE
fields:
idService:
id: true
type: integer
unsigned: false
nullable: false
column: ID_SERVICE
generator:
strategy: IDENTITY
codeService:
type: string
length: 5
fixed: false
nullable: false
column: CODE_SERVICE
dateCreation:
type: date
nullable: false
column: DATE_CREATION
dateModification:
type: date
nullable: false
column: DATE_MODIFICATION
In my database, I have a BEFORE INSERT Trigger that set dateCreation and dateModification.
I'd like to let him do his job, but when I persist a new entity, I got this SQL error :
An exception occurred while executing 'INSERT INTO SERVICE (CODE_SERVICE, DATE_CREATION, DATE_MODIFICATION) VALUES (?, ?, ?)' with params ["test", null, null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'DATE_CREATION' cannot be null
Is there a way to do this ? I know triggers are bad, but I don't have any choice...
Here is the trigger, it works :
CREATE TRIGGER `SERVICE_BI_TG` BEFORE INSERT ON `SERVICE` FOR EACH ROW BEGIN
BEGIN
SET NEW.DATE_CREATION=NOW();
SET NEW.DATE_MODIFICATION=NOW();
END
The problem is that I have some other fields set on INSERT or UPDATE, like some foreign key and some UPDATE on other tables, I simplified it for my post.