Abstract Entity Events not fired (porting from sequelize)

Hello,
following suggestions from Wagner Landgraf in reply to a previous request of mine:

I have prepared a TSeqEntity abstract class with [OnInserting] and [OnUpdating] attributes - this class has the directive {$RTTI EXPLICIT METHODS([vcPrivate..vcPublished])}

Then, Tcom_plants = class(TSeqEntity) - which inherits from TSeqEntity correctly inherits the createdAt & updatedAt properties... but no event is fired from the parent class.

I've also tried to debug code in Delphi 11.3... but the breakpoints are green - that's a signal that the code is never reached... any suggestion?

Thanks in advance!

Do you have a small sample project reproducing the issue so we can better investigate the reason why it's not working?

Hello Wagner,

I'm attaching a sample project, it's based on MySQL (you can create db with SQL/tms_test.sql - credentials sysdba:masterkey).
I have kept everything as-is from TMS XData VCL Server wizard, just added FDConnection1 and the two files.

DefaultEntitySetPermissions all true - the idea is to test via SwaggerUI.

PATCH does not update updatedAt field (I've tried calling it with body { "isActive": 0 } )

PUT fails to insert a new record "[FireDAC][Phys][MySQL] Field 'createdAt' doesn't have a default value"

Aurelius_Sequelize.zip (96.2 KB)

Delphi linker is removing the methods OnInserting and OnUpdating. Either:

  1. Put them in public section; or
  2. Flag them as virtual; or;
  3. Move the {$RTTI} directive to the beginning of the unit.

Then it should work.

1 Like

Many thanks - it works like a charm, now.

I had NO idea the position of the directive was important... after your suggestion I've found here some remarks on positions:
https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Delphi_compiler_directives

if the the RTTI directive is put on top (before unit name declaration) the compiler gives this message
[dcc32 Error] CTS.Entities.SEQ.CrAt_UpAt.pas(1): E2609 RTTI directive must be used after PROGRAM, UNIT or LIBRARY header

the solution was then to put the directive just after unit and before interface sections.

Many thanks again - have a nice weekend :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.