#1 2021-10-10 20:31:52

tbo
Member
Registered: 2015-04-20
Posts: 338

Base class for TOrm with property IDValue

Concerns mORMot2

Note: The following change is not necessary but useful and convenient in my case. wink

Class inheritance:
TObjectWithCustomCreate -> TBaseOrm -> TOrm
The TBaseOrm class should only have the IDValue property that it remains lightweight.

As I described in this thread, for interface passed services I use on the server objects inherited from class TOrm and on the client the same objects as business objects, only here they are inherited from class TBom (with simple compiler switches). Class TBom is currently inherited from TObjectWithCustomCreate and has only one property IDValue. The client also has classes inherited from TOrm that use the local database, so I always have to write the following:

if ((SourceObject is TOrm) and (TOrm(SourceObject).IDValue ...))
  or ((SourceObject is TBom) and (TBom(SourceObject).IDValue ...)) then ...

If TOrm had a base class TBaseOrm with the IDValue property, I could shorten it as follows:

if (SourceObject is TBaseOrm) and (TBaseOrm(SourceObject).IDValue ...) then ...

With best regards
Thomas

Offline

#2 2021-10-11 07:30:54

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

Re: Base class for TOrm with property IDValue

So what you propose is to make KDD even one step further, and ignore the whole TOrm features, and expose the same class properties, either as TOrm or as TObjectWithID.
It is a complex but clever trick.

I have introduced a TObjectWithID class, new parent of TOrm, for your purpose.
Your idea of having an ORM-agnostic class on client side may be part of mORMot itself in the future.

Offline

#3 2021-10-11 17:02:08

tbo
Member
Registered: 2015-04-20
Posts: 338

Re: Base class for TOrm with property IDValue

ab wrote:

So what you propose is to make KDD even one step further, and ignore the whole TOrm features, and expose the same class properties, either as TOrm or as TObjectWithID.
It is a complex but clever trick.

Thank you for the kind words and the quick implementation. This makes my day. smile

With best regards
Thomas

Offline

Board footer

Powered by FluxBB