Architectural problem with recreating entities

Notice: This thread is very old.
dimkalinux
Member | 24
+
0
-

Hi all.

For learn Nette framework 2.0.11 i'm starting development small project. It use base structure from nette.addons project from github. I have 3 entity (models) – A, B, C and like nette.addons recreate it from DB use static method A::fromActiveRow($row). Each entity have related other entity (A → B → C) and this scheme works – i can create A that create collections of B and each B create C (all have static method fromActiveRow($row)). But now i change that C stored not database – in file. I created CRepository service that have parameter $storageDir (wired in config) where C data is saved. CRepository can create C-entity because is known $strogeDir. But now i can not recreate C from B entity because C is not have $storageDir parameter (its CRepository responsibility). I have situation when C can not recreate self because it have no information where and how it saved.

Technically C its just extracted to new model two big text column from B.

First creation work great because its placed in Presenters that injects Repositories. Problem with restoring entities.

Any idea how handle this? Seems like DI is good for Presenters, but i have no idea how use DI-containers in models.

Last edited by dimkalinux (2013-08-09 21:20)

enumag
Member | 2118
+
0
-

A::fromActiveRow(...) seems bad for me, I'd use sth like $aRepository->createEntityFromActiveRow(...).

dimkalinux
Member | 24
+
0
-

enumag, i don't like A:fromActiveRow too, but in your method for creating B-entity in A – i need pass $bRepository to A-entity. I don't think that passing repository
to entity is good idea. Or I'm wrong?

enumag
Member | 2118
+
0
-

Passing repository to entity is bad idea.

You could use $aRepository->createEntity($activeRow, $bEntity).

dimkalinux
Member | 24
+
0
-

Yes, but if i have chain of Enities like AddonEntity have collection of TagEntity. And i want to display AddonEntity on page with Tags. In ShowPressenter i inject AddonRepository and load from database and recreating AddonEntity by id. At this moment in AddonEntity i can not load (recreate) collections of TagEntity because AddonEntity don't have TagRepository.

dimkalinux
Member | 24
+
0
-

I will try move all code in *:fromActiveRow($row) to Repositories. Is not good that entity is known about database. Too much information for entity level.