orm icon indicating copy to clipboard operation
orm copied to clipboard

How to properly use nette/di lazy feature with nextras/orm

Open mrceperka opened this issue 1 month ago • 5 comments

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

mrceperka avatar Nov 12 '25 11:11 mrceperka

So far the only downside of this approach is that all repositories/metadata are now initialized eagerly. But overall it's still worth.

mrceperka avatar Nov 12 '25 12:11 mrceperka

That was always the point/case to allow "wild" new Entity().

hrach avatar Nov 12 '25 13:11 hrach

@hrach You already fixed the issue, it's just not released :D https://github.com/nextras/orm/commit/5770ec43638833f92ec7026d26d033584ff96cd1#diff-d1faaab19a6e495a9433fe61e92ba95fce98be072a39d386fe93d2ea9b9abd4aR209-R210

mabar avatar Nov 18 '25 21:11 mabar

Yes, we discussed it, and it doesn't work. This issue is reminder to investigate a bit more.

hrach avatar Nov 18 '25 22:11 hrach

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)

mabar avatar Nov 19 '25 00:11 mabar