#1 2019-10-02 00:53:14

israel_jbl
Member
Registered: 2019-08-29
Posts: 5

How handle self referencing table

I have this PODO:

  TDomZone = class(TSynPersistent)
  private
    FParentZone: TDomZone;
    FZoneType: RawUTF8;
    FCode: RawUTF8;
    FISOCode: RawUTF8;
    FName: RawUTF8;
    FLatitude: Double;
    FLongitude: Double;
    FAltitude: Double;
  published
    property ParentZone: TDomZone read FParentZone write FParentZone;
    property &ZoneType: RawUTF8 read FZoneType write FZoneType;
    property Code: RawUTF8 read FCode write FCode;
    property ISOCode: RawUTF8 read FISOCode write FISOCode;
    property Name: RawUTF8 read FName write FName;
    property Latitude: Double read FLatitude write FLatitude;
    property Longitude: Double read FLongitude write FLongitude;
    property Altitude: Double read FAltitude write FAltitude;
  end;

  TSQLZone = class(TSQLRecord)
  ...
  published
     ParentZone: TSQLZone;
  ...
  end;

...Interfaces...
...Repository...
...Factory...

TInterfaceFactory.RegisterInterfaces([TypeInfo(IDomZoneQuery), TypeInfo(IDomZoneCommand)]);

Self referencing attribute ParentZone. I'm using SOA. The framework throw Access Violation in some where else, I don't know why, but if I comment the RegisterInterfaces line, it works.

Stacktrace:

mORMot.JSONObjectFromClass(TClass($445F4244),$315BCC8)
mORMot.TJSONSerializer.WriteObject($323A044,[woDontStoreDefault])
mORMot.WriteProp($849C84)
mORMot.WritePropsFromRTTI(TClass($849B64))
mORMot.TJSONSerializer.WriteObject($32555E8,[woDontStoreDefault])
mORMot.TServiceMethodArgument.AddJSON($326B450,$3228C38,[woDontStoreDefault])
mORMot.TServiceMethodExecute.ExecuteJson((...),'[]',$326B450,$5BDF6A0 {''},False)
mORMot.TServiceFactoryServer.ExecuteMethod($320C460)
mORMot.ComputeResult
mORMot.TSQLRestServerURIContext.InternalExecuteSOAByInterface
mORMot.TSQLRestRoutingREST.ExecuteSOAByInterface
mORMot.TSQLRestServerURIContext.ExecuteCommand
mORMot.TSQLRestServer.URI($5BDFBE4)
mORMotHttpServer.TSQLHttpServer.Request($3246AC8)
SynCrtSock.THttpServerGeneric.Request($3246AC8)
SynCrtSock.THttpApiServer.Execute
System.Classes.ThreadProc($3786050)
System.ThreadWrapper($3228CF0)
:75370419 KERNEL32.BaseThreadInitThunk + 0x19
:7763662d ntdll.RtlGetAppContainerNamedObjectPath + 0xed
:776365fd ntdll.RtlGetAppContainerNamedObjectPath + 0xbd


How I should handle self referencing tables?

I love  your framework, crazy it is free, thanks!

Offline

#2 2019-10-02 11:39:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: How handle self referencing table

In the ORM, so for TSQLRecord, published fields inheriting from TSQLRecord are not true instances, but just a mapping to the ID, to create a one-to-one relationship at SQL level.
See the documentation.

Offline

Board footer

Powered by FluxBB