#1 2015-10-14 16:41:12

zed
Member
From: Belarus
Registered: 2015-02-26
Posts: 102

Build 1.18.1991 - TSQLRecord class inherits bug?

I have some class inherits:

TSQLMyTable = class(TSQLRecord)
private
  ...
published
  ...
end;

TSQLMyTableA = class(TSQLMyTable)
private
  ...
published
  ...
end;

TSQLMyTableB = class(TSQLMyTable)
private
  ...
published
  ...
end;

I create a model depends on used DB:

if ... then
  FModel := TSQLModel.Create([TSQLMyTableA])
else
  FModel := TSQLModel.Create([TSQLMyTableB]);

Then I call VirtualTableExternalRegister and register table as "MyTable" in any case. So in ORM level I can access only to the base fields from TSQLMyTable. But also I can excec some direct sql requests with optimisations for different DB using custom fields from TSQLMyTableA or TSQLMyTableB. All this worked perfectly until your last commit (1.18.1991), now it rises exception: 'TSQLModel must include TSQLMyTable' in GetTableIndexSafe sad

Last edited by zed (2015-10-14 17:07:14)

Offline

#2 2015-10-14 17:12:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,267
Website

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

I guess you have a published field pointing to an abstract TSQLMyTable...

Now we are ensuring the pointed table is available when using external references.
It is needed for proper cascading during deletion operations...

Could you tell us more about the TSQLMyTable* relationship?

Online

#3 2015-10-14 17:33:02

zed
Member
From: Belarus
Registered: 2015-02-26
Posts: 102

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

My original declarations:

...
  TSQLMark = class(TSQLRecord)
  public
    FCategory: TSQLCategory;
    FImage: TSQLMarkImage;
    FAppearance: TSQLMarkAppearance;
    FName: RawUTF8;
    FDesc: RawUTF8;
    FGeoType: TSQLGeoType;
    FGeoCount: Cardinal;
    FGeoLonSize: Cardinal;
    FGeoLatSize: Cardinal;
    FGeoWKB: TSQLRawBlob;
  published
    property mCategory: TSQLCategory read FCategory write FCategory;
    property mImage: TSQLMarkImage read FImage write FImage;
    property mAppearance: TSQLMarkAppearance read FAppearance write FAppearance;
    property mName: RawUTF8 read FName write FName;
    property mDesc: RawUTF8 read FDesc write FDesc;
    property mGeoType: TSQLGeoType read FGeoType write FGeoType;
    property mGeoCount: Cardinal read FGeoCount write FGeoCount;
    property mGeoLonSize: Cardinal read FGeoLonSize write FGeoLonSize;
    property mGeoLatSize: Cardinal read FGeoLatSize write FGeoLatSize;
    property mGeoWKB: TSQLRawBlob read FGeoWKB write FGeoWKB;
  end;

  TSQLMarkClass = class of TSQLMark;

  TSQLMarkDBMS = class(TSQLMark)
  public
    FLeft, FRight, FBottom, FTop: Cardinal;
  published
    property mLeft: Cardinal read FLeft write FLeft;
    property mRight: Cardinal read FRight write FRight;
    property mBottom: Cardinal read FBottom write FBottom;
    property mTop: Cardinal read FTop write FTop;
  end;

  TSQLMarkMongoDB = class(TSQLMark)
  public
    FGeoJsonIdx: Variant;
  published
    property mGeoJsonIdx: Variant read FGeoJsonIdx write FGeoJsonIdx;
  end;

  TSQLMarkView = class(TSQLRecord)
  public
    FUser: TSQLUser;
    FMark: TSQLMark;
    FCategory: TSQLCategory;
    FVisible: Boolean;
  published
    property mvUser: TSQLUser read FUser write FUser;
    property mvMark: TSQLMark read FMark write FMark;
    property mvCategory: TSQLCategory read FCategory write FCategory;
    property mvVisible: Boolean read FVisible write FVisible;
  end;
...

And yes, in my TSQLMarkView I have field that pointing to TSQLMark. What can I do in this case? Change field type declaration in TSQLMarkView form TSQLMark to TID?

Offline

#4 2015-10-14 19:25:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,267
Website

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

Yes, TID is the safe way to do it.

You would never create a TSQLMark instance in any case....

Online

#5 2015-10-15 09:13:04

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 415

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

I have the same message cause we derive a class from TSQLAuthUser and TSQLAuthGroup.
What can we do here ? (atm we rewinded to 1.18.1989)
AB you're right, we never will have a table of this class and use this for a long time now.
Cascading delete we also do not need !

Last edited by itSDS (2015-10-15 09:14:23)


Rad Studio 11.1

Offline

#6 2015-10-15 09:15:35

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 415

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

  TDFSQLAuthUser = class(TSQLAuthUser)
  public
    class procedure InitializeTable(Server: TSQLRestServer; const FieldName: RawUTF8; Options: TSQLInitializeTableOptions); override;
  end;

  TDFSQLAuthGroup = class(TSQLAuthGroup)
  public
    class procedure InitializeTable(Server: TSQLRestServer; const FieldName: RawUTF8; Options: TSQLInitializeTableOptions); override;
  end;

Rad Studio 11.1

Offline

#7 2015-10-15 09:17:26

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 415

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

As you stated above you have to rewrite TSQLAuthUser that tGroup is form Type TID now.

I think that is not what you wanted - or ?


Rad Studio 11.1

Offline

#8 2015-10-15 09:19:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,267
Website

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

Why does it affect TSQLAuthUser?

Those tables are a special case.
You could still use in this case a true class, since the mORMot.pas creates its own instances with the registered user/group classes.

Online

#9 2015-10-15 09:25:44

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 415

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

the only thing i did to TSQLAuthUser/Group was to derive it an add Initialize Proc.

Now we get the error that TSQLAuthGroup is not registered cause TSQLAuthUser references to it.

In Former Version this was no Problem !

Now my Question what can we do.
I think there is a conceptual error if i can not refer to derived classes.


Rad Studio 11.1

Offline

#10 2015-10-15 10:40:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,267
Website

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

Please try http://synopse.info/fossil/info/5293458f2b

I made some modifications to the code so that it allows lazy initialization of the table class.
But of course, cascaded deletion of the foreign keys properties would work only if the published field class is an exact match.
wink

Online

#11 2015-10-15 11:39:12

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 415

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

tyvm, i actually did not dig into the deep. But we don't use cascading deletes. We delete the depending records by hand ...


Rad Studio 11.1

Offline

#12 2015-10-15 12:09:41

zed
Member
From: Belarus
Registered: 2015-02-26
Posts: 102

Re: Build 1.18.1991 - TSQLRecord class inherits bug?

I don't use cascading deletes too and with your last fixes my code works fine, again smile

Offline

Board footer

Powered by FluxBB