symfony-cmf / symfony-cmf

Meta package tying together all the key packages of the Symfony CMF project.
http://cmf.symfony.com
Other
729 stars 94 forks source link

[RFC] Add ORM support using proxies #240

Open wouterj opened 7 years ago

wouterj commented 7 years ago

We want to add ORM support for a long time, but are always facing a big issue: There is no way to allow dynamic content to be bound to routes or the like. E.g. the same route entity should be able to bind to StaticContent and Page.

This morning, I came up with a solution for this: As content property, save the class of the content object and it's identifier. When fetching the route, return a proxy of the route object. As soon as $route->getContent() is called, fetch the content object from the database and return it. This can of course be applied to any entity that requires it.

This means that 2 queries are needed, but I don't think we can make ORM as optimized as PHPCR. PHPCR is, after all, the first class citizen and main feature of the CMF.

dbu commented 7 years ago

this would certainly be doable, yes. people will not read the warning that this can be a bit slow, and be surprised about performance issues when they have a site that grows big. but i think the approach is sensible.

there were several attempts at "doctrine bridges" that would allow to link entity/document between storages, doctrine variants or with other sources. your approach sounds like re-doing that for a particular case. but it would just be one implementation of a repository, thus i don't have a big issue with that. and it would be more contained than adding one of those bridges (that afaik none are up-to date and maintained, so not production-ready)