How to properly use nette/di lazy feature with nextras/orm
We've come up with solution that works but it required more steps then we expected.
First, you set nette/di lazy to true
di:
lazy: true
Then you have to force nextras/orm extension to initializeMetadata
orm:
model: App\Core\Model\Orm
initializeMetadata: true
Then you also HAVE TO DISABLE lazy for orm.metadataStorage
orm.metadataStorage
lazy: false
Aaand it probably works, bit complicated setup tho :D
Is there any better way right know? Thanks
So far the only downside of this approach is that all repositories/metadata are now initialized eagerly. But overall it's still worth.
That was always the point/case to allow "wild" new Entity().
@hrach You already fixed the issue, it's just not released :D https://github.com/nextras/orm/commit/5770ec43638833f92ec7026d26d033584ff96cd1#diff-d1faaab19a6e495a9433fe61e92ba95fce98be072a39d386fe93d2ea9b9abd4aR209-R210
Yes, we discussed it, and it doesn't work. This issue is reminder to investigate a bit more.
Hmm, that's weird. Method is called on that service, therefore it should be initialized right away 🤔
Perhaps we could just always enable the option and set lazy: false on the service, so it's no config. Or at least enable it when di > lazy is enabled. (It's easy to find the option value - get extension by name and get it's config. di extension can't be renamed and the loading order is fixed, therefore it will just work)