@@ -166,10 +166,15 @@ TSession = class(TAbstractSession)
166
166
function FindAll <T: class , constructor >: IList<T>;
167
167
168
168
// / <summary>
169
- // / Inserts model to the database .
169
+ // / Inserts model to the database.
170
170
// / </summary>
171
171
procedure Insert (const entity: TObject);
172
172
173
+ // / <summary>
174
+ // / Inserts model and its aggregations to the database.
175
+ // / </summary>
176
+ procedure InsertAll (const entity: TObject);
177
+
173
178
// / <summary>
174
179
// / Inserts models to the database.
175
180
// / </summary>
@@ -182,12 +187,17 @@ TSession = class(TAbstractSession)
182
187
function IsNew (const entity: TObject): Boolean;
183
188
184
189
// / <summary>
185
- // / Updates model in a database.
190
+ // / Updates model in the database.
186
191
// / </summary>
187
192
procedure Update (const entity: TObject);
188
193
189
194
// / <summary>
190
- // / Updates multiple models in a database.
195
+ // / Updates model and its aggregations in the database.
196
+ // / </summary>
197
+ procedure UpdateAll (const entity: TObject);
198
+
199
+ // / <summary>
200
+ // / Updates multiple models in the database.
191
201
// / </summary>
192
202
procedure UpdateList <T: class , constructor >(const entities: IEnumerable<T>);
193
203
@@ -447,6 +457,25 @@ procedure TSession.Insert(const entity: TObject);
447
457
DoInsert(entity, inserter);
448
458
end ;
449
459
460
+ procedure TSession.InsertAll (const entity: TObject);
461
+ var
462
+ relations: IList<TObject>;
463
+ relation: TObject;
464
+ entityWrapper, foreignEntityWrapper: IEntityWrapper;
465
+ begin
466
+ TRttiExplorer.GetRelationsOf(entity, ManyToOneAttribute).ForEach(Insert);
467
+ Insert(entity);
468
+
469
+ entityWrapper := TEntityWrapper.Create(entity);
470
+ relations := TRttiExplorer.GetRelationsOf(entity, OneToManyAttribute);
471
+ for relation in relations do
472
+ begin
473
+ foreignEntityWrapper := TEntityWrapper.Create(relation);
474
+ UpdateForeignKeysFor(foreignEntityWrapper, entityWrapper);
475
+ InsertAll(relation);
476
+ end ;
477
+ end ;
478
+
450
479
procedure TSession.InsertList <T>(const entities: IEnumerable<T>);
451
480
var
452
481
inserter: IInsertCommand;
@@ -515,10 +544,10 @@ procedure TSession.SaveAll(const entity: TObject);
515
544
TRttiExplorer.GetRelationsOf(entity, ManyToOneAttribute).ForEach(Save);
516
545
Save(entity);
517
546
547
+ entityWrapper := TEntityWrapper.Create(entity);
518
548
relations := TRttiExplorer.GetRelationsOf(entity, OneToManyAttribute);
519
549
for relation in relations do
520
550
begin
521
- entityWrapper := TEntityWrapper.Create(entity);
522
551
foreignEntityWrapper := TEntityWrapper.Create(relation);
523
552
UpdateForeignKeysFor(foreignEntityWrapper, entityWrapper);
524
553
SaveAll(relation);
@@ -578,6 +607,25 @@ procedure TSession.Update(const entity: TObject);
578
607
DoUpdate(entity, updater);
579
608
end ;
580
609
610
+ procedure TSession.UpdateAll (const entity: TObject);
611
+ var
612
+ relations: IList<TObject>;
613
+ relation: TObject;
614
+ entityWrapper, foreignEntityWrapper: IEntityWrapper;
615
+ begin
616
+ TRttiExplorer.GetRelationsOf(entity, ManyToOneAttribute).ForEach(Update);
617
+ Update(entity);
618
+
619
+ entityWrapper := TEntityWrapper.Create(entity);
620
+ relations := TRttiExplorer.GetRelationsOf(entity, OneToManyAttribute);
621
+ for relation in relations do
622
+ begin
623
+ foreignEntityWrapper := TEntityWrapper.Create(relation);
624
+ UpdateForeignKeysFor(foreignEntityWrapper, entityWrapper);
625
+ UpdateAll(relation);
626
+ end ;
627
+ end ;
628
+
581
629
procedure TSession.UpdateList <T>(const entities: IEnumerable<T>);
582
630
var
583
631
updater: IUpdateCommand;
0 commit comments