From f0bbcb86d70d045542c7f8fc9eda2ba6085413e3 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Mon, 4 May 2020 09:48:51 +0200 Subject: [PATCH] Children object lifecycle management in MVCActiveRecord --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 8b88a147..c5e7b5d1 100644 --- a/README.md +++ b/README.md @@ -458,6 +458,44 @@ end; - New! The **MVCAREntitiesGenerator** can optionally register all the generated entities also in the `ActiveRecordMappingRegistry` (Thanks to [Fabrizio Bitti](https://twitter.com/fabriziobitti) from [bit Time Software](http://www.bittime.it)) +- New! Children objects lifecycle management in `TMVCActiveRecord` (methods `AddChildren` and `RemoveChildren`). Really useful to manage child objects such relations or derived properties and are safe in case of multiple addition of the same object as children. + + ```delphi + //Having the following declaration + + type + [MVCNameCase(ncCamelCase)] + [MVCTable('authors')] + TAuthor = class(TPersonEntityBase) + private + fBooks: TEnumerable; + [MVCTableField('full_name')] + fFullName: string; + function GetBooks: TEnumerable; + public + [MVCNameAs('full_name')] + property FullName: string read fFullName write fFullName; + property Books: TEnumerable read GetBooks; + end; + + + //method GetBooks can be implemented as follows: + + implementation + + function TAuthor.GetBooks: TEnumerable; + begin + if fBooks = nil then + begin + fBooks := TMVCActiveRecord.Where('author_id = ?', [ID]); + AddChildren(fBooks); //fBooks will be freed when self will be freed + end; + Result := fBooks; + end; + ``` + + + - **JSON-RPC Improvements** - New! Added `TMVCJSONRPCExecutor.ConfigHTTPClient` to fully customize the inner `THTTPClient` (e.g. `ConnectionTimeout`, `ResponseTimeout` and so on)