#1 2016-03-21 17:39:16

MiniMatrix
Member
Registered: 2016-03-21
Posts: 4

Dynamic fields in class definition

Hi

This is a total mORMot newbe question. Sorry :-) Also for probably ugly English :-|

Reading the documentation of the mORMot classes I wondered, why there is no possibility to define dynamic fields. Okay, it is possible to define them, but they can only be stored in a blob field (hope, I did not read over something). But this is not, what I like to do.

If I create an application using mORMot, it is very nice to define a class which fields are automatically "bind" to a SQL table (ORM). This is very helpful for application design, because this is not changeable by customers - we do not need to check, if they exist.
But today it is very interesting for customers to enhance an existing application by there needs. I think about an address application, as an example, where a person can be defined with address information such as Street, ZipCode, etc. This additional address data is stored in an extra db table, not in the person one (this can be done all by mORMot).
Now the customer needs for whatever reason 50 (or more) additional/individual fields, which should not be implemented in the standard application, but should be accessible as normal fields in the database tables (probably because of reporting requirements - ODBC,...). How can this be handled?
It should be possible to define one or more "empty" table definitions (classes), with no table columns (properties) in the standard application (better woud be if this could also be defined "dynamicly"). But what is about the fields? Ok, they could be created using SQL statements. But this is not the ORM model style.

If it is not possible - as I think actual - with the current version of mORMot, the following solution would be great.

Each class definition (for persistent datas in db - e.g. TSQLRecord) should have a property DynFieldDefs (like FieldDefs of TDataset) in the underlying base class, where additional fields can be defined. These definitions are stored in the destination database, where the corresponding table is in, for use when the structure of the model is beeing checked or rebuild.
Instead of reading the class property itself directly, the property DynFieldsDefs has to be used for it. Each object returned by this list can have a property .AsSting, .AsInteger, ... to get or write corresponding values to it (TIntFieldType, TStrFieldType, TVarFieldType, ...). Using a spezial methode (propably it already exists) the data model could be refreshed to update the database structure (directly at runtime, or later (yyyy.mm.dd hh.nn.ss)).

Am I wrong with my view of things, that this is missed in mORMot?

Offline

#2 2016-03-21 19:48:32

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

Re: Dynamic fields in class definition

Such dynamic fields are already fully implemented using variant fields, and TDocVariant content.
See the doc about this feature.

Offline

Board footer

Powered by FluxBB