You are not logged in.
Pages: 1
Hello,
Environment: Delphi XE2, TRestServerDB, SQLite3 database, 4 tables in a model, one of the tables references another by a TClassNameToBeDeletedID field.
It appears that the TClassNameToBeDeletedID does not work as expected: the field index is not created and (I suspect) the cascade deletion does not work either.
I have found the immediate cause for this in the unit mormot.orm.core but deeper details elude me.
constructor TOrmPropInfoRttiTID.Create(aPropInfo: PRttiProp; aPropIndex: integer; aOrmFieldType: TOrmFieldType; aOptions: TOrmPropInfoListOptions);
...
if IdemPropName(TypeName^, 'TID') or
(ord(TypeName^[1]) and $df <> ord('T')) or // expect T...ID pattern
(PWord(@TypeName^[L - 1])^ and $dfdf <> ord('I') + ord('D') shl 8) or
(Rtti.Counts[rkClass] = 0) then
exit;
if (L > 13) and IdemPropName('ToBeDeletedID', @TypeName^[L - 12], 13) then
begin // 'TOrmClientToBeDeletedID' -> TOrmClient + CascadeDelete=true
fCascadeDelete := true;
Found := Rtti.FindName(@TypeName^[1], L - 13, rkClass);
end
...
end;
The condition (Rtti.Counts[rkClass] = 0) is False. If it is commented out then the code works as expected.
Best regards,
Sergey
Offline
It appears that I have found the problem: it is in the unit mormot.core.rtti.
It seems to me that instead of
inc(Counts[Instance.Kind]);
the following code should be used in the procedure TRttiCustomList.AddToPairs(Instance: TRttiCustom; Info: PRttiInfo):
inc(Counts[Info.Kind]);
When the AddToPairs is called from the function TRttiCustomList.DoRegister
// initialize a new TRttiCustom/TRttiJson instance for this type
result := GlobalClass.Create;
// register ASAP to avoid endless recursion in FromRtti
AddToPairs(result, Info);
// now we can parse and process the RTTI
result.FromRtti(Info);
the first parameter (result) is not completely initialized yet and the Instance.Kind always equals to rkUnknown inside the AddToPairs. Therefore, the correct counters in the array are not incremented.
Offline
You are right!
Please try with https://github.com/synopse/mORMot2/commit/306a0cfa
Offline
Thank you!
Offline
Pages: 1