You are not logged in.
Pages: 1
In mORMot1 I used to use TCollection a lot as described in the documentation in 5.5.2.1.2.3. TPersistent/TCollection fields. This also worked in mORMot2 until commit 88742d0 several ORM raw optimizations.
As far as I can see the create constructor was changed to InternalCreate which does not call the overloaded Create constructor anymore.
So the TCollection is not created anymore, is null and can't be set when getting data from the database.
constructor TSQLRecordPeopleObject.Create;
begin
inherited;
fPersistent := TCollTst.Create;
fUTF8 := TRawUTF8List.Create;
end;
Please find a test example in https://gist.github.com/martin-doyle/a4 … 18facfad6c.
Is TCollection still supported and what is the recommended way of using it?
Offline
Is TCollection still supported and what is the recommended way of using it?
You are right, now you have to write the following:
procedure TTestData.TestRetreiveOrmWithCollection;
...
TestClient := TRestClientDB.Create(FModel, nil, DataFile, TRestServerDB, false, '');
try
Order := TOrmOrderBook.Create;
try
if Order.FillPrepare(TestClient.Orm, '', []) then
begin
The documentation is also not entirely clear at this point. Let's see what Arnaud says when he gets back.
With best regards
Thomas
Offline
Thanks Thomas, that keeps me working.
I was only able finding the right commit and spot. This fix helps a lot.
Offline
The same happens when using one of the Create functions with paramters.
Order := TOrmOrderBook.Create(TestClient.Orm, 'OrderNo = ?', ['Order1']);
The work around is currently using the Retrieve function like
Order := TOrmOrderBook.Create;
try
TestClient.Orm.Retrieve('OrderNo = ?', [], ['Order1'], Order);
I updated the tests in https://gist.github.com/martin-doyle/6c … a26990e46e.
By the way, I like the idea of embedding detail data within the record (sharding). Would be interesting to know what other people use, just schemaless TDocVariant?
Offline
By the way, I like the idea of embedding detail data within the record (sharding). Would be interesting to know what other people use, just schemaless TDocVariant?
I mostly (always) use sharding, together with json storage. Keeps the raw database data in a format that also can be read by other applications not based on the mORMot.
Offline
By the way, I like the idea of embedding detail data within the record (sharding). Would be interesting to know what other people use, just schemaless TDocVariant?
I use it in conjunction with SOA and WebApps (TMcvApplication) when records are mostly just read, and can recommend it. This saves many JOINs when combining the data from different tables of the DB. As an example, you have events with presentations. In the overview are displayed: Date, topic, location, room, speaker, etc. Only the date comes from the schedule table. Everything else are foreign keys into other tables. Having an extra field here that contains all the data from other tables needed for display reduces the effort considerably and makes viewing fast. And because the data composition changes very rarely and everything is handled via SOA functions, it is practically no effort to maintain this field.
With best regards
Thomas
Offline
In mORMot1 I used to use TCollection a lot as described in the documentation in 5.5.2.1.2.3. TPersistent/TCollection fields. This also worked in mORMot2 until commit 88742d0 several ORM raw optimizations.
As far as I can see the create constructors was changed to InternalCreate which does not call the overloaded Create constructor anymore.
Create with parameters and CreateAndFiilPrepare don’t work anymore. Any recommendations how to use TCollection and TPersistance from now on?
Please see the tests in https://gist.github.com/martin-doyle/6c … a26990e46e.
Offline
Create with parameters and CreateAndFiilPrepare don’t work anymore. Any recommendations how to use TCollection and TPersistance from now on?
You make the same mistake again. If you do your own initializations in the constructor of an ORM object, you can NEVER take the overloaded constructors as long as Arnaud solved the problem with InternalCreate function. The overridden constructor is not called and thus the own variable classes are not initialized and all calls go to nothing. I think that this change of Arnaud was very unfortunate, but currently it is as it is. Change it as follows:
procedure TTestData.TestCreateAndFillPrepare;
...
Order := TOrmOrderBook.Create; // AndFillPrepare(TestClient.Orm, '', []);
try
Order.FillPrepare(TestClient.Orm, '', []);
procedure TTestData.TestCreate;
...
Order := TOrmOrderBook.Create; // (TestClient.Orm, 'OrderNo = ?', ['Order1']);
try
TestClient.Orm.Retrieve(FormatUtf8('OrderNo = ?', [], ['Order1']), Order);
I think if you want changes, you need to push Arnaud a little bit.
With best regards
Thomas
Last edited by tbo (2023-06-19 18:46:53)
Offline
Please try https://github.com/synopse/mORMot2/commit/a056b7f9
You should now override InternalCreate instead of Create.
Online
Works perfectly.
TOrmOrderBook = class(TOrm)
…
public
procedure InternalCreate;override;
procedure TOrmOrderBook.InternalCreate;
begin
inherited InternalCreate;
FItems := TItemCollection.Create(TItem);
end;
Thanks a lot.
Offline
Pages: 1