How to deal with ODM and ORM

38 views
Skip to first unread message

Bruno Reis

unread,
May 1, 2015, 2:10:26 PM5/1/15
to symfony-...@googlegroups.com
One of the reasons I've chosen the symfony cmf is because I will also be able to develop thing using symfony / orm. But I'm facing some design questions right now. 

I've created the user table in the orm, but I've created some other entities on the ODM. But, some of those have direct relations with the users. How are you dealing with that? 

I will be grateful if you can share your experiences and design decisions. 

Jonathan Wage

unread,
May 1, 2015, 2:34:41 PM5/1/15
to symfony-...@googlegroups.com
Take a look at this:


You can use the postLoad events to set the cross mapper references.

- Jon

--
You received this message because you are subscribed to the Google Groups "symfony-cmf-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony-cmf-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Connect with me on http://twitter.com/jwage

Bruno Reis

unread,
May 1, 2015, 2:53:09 PM5/1/15
to symfony-...@googlegroups.com
Thanks a lot Jonathan. That sure will help. 

I'd also like to understand the driving forces behind design decisions. 
What should I put on odm and what on orm? And why?

If anyone has any ideas on that, please share. 

Jonathan Wage

unread,
May 1, 2015, 3:57:33 PM5/1/15
to symfony-...@googlegroups.com
I would probably recommend not using multiple databases and just use the ORM and one database for everything. Unless you have a strong use cases that you can clearly define as being better in a non relational database then I would just go with one database. My guess is you would be hard pressed to find a use case that wouldn't just work in a RDBMS.

- Jon

Bruno Reis

unread,
May 1, 2015, 4:06:59 PM5/1/15
to symfony-...@googlegroups.com
In this specific project, I have a lot of content editing and needs that made me choose the symfony cmf. 

Jonathan Wage

unread,
May 1, 2015, 4:46:54 PM5/1/15
to symfony-...@googlegroups.com
Sorry, ignore me :) I misunderstood. When you said ODM you were referring to the CMF ODM. I thought you meant like MongoDB ODM or CouchDB ODM or something.

As for your original question of where to put things, it seems like all content/cms type of data would go in the ODM and other stuff would go in the ORM. I haven't actually used the CMF so someone else who has experience might be able to answer better.

David Buchmann

unread,
May 2, 2015, 4:45:56 AM5/2/15
to symfony-...@googlegroups.com
> Thanks a lot Jonathan. That sure will help.
>
> I'd also like to understand the driving forces behind design decisions.
> What should I put on odm and what on orm? And why?
>
> If anyone has any ideas on that, please share.

my rule of thumb is that if its cms / tree things with content and
pictures, its phpcr-odm and when its very structured things and
especially when i want to do aggregations or update sql queries, i would
put it in a relational database.

in an e-commerce example, product descriptions and the navigation tree
could go in phpcr-odm, while stock information and orders go into a RDBMS.

i hope this helps,
david

Bruno Reis

unread,
May 2, 2015, 10:27:44 AM5/2/15
to symfony-...@googlegroups.com
Thanks David, 

I have some contents that are CMF likely, but they have some lists of users associated with them. 

The way I'm dealing with it is to overwrite the controller, injecting one that extends from the ContentController and load this users in there, using the proposed "getParams" extension point. But it feels a little cumbersome.  

A better way would be having some kind of "proxy"in the document and be able to load this users on demand, navigating through the model. Any ideas of an easy way to do that? 

David Buchmann

unread,
May 2, 2015, 10:40:24 AM5/2/15
to symfony-...@googlegroups.com
> I have some contents that are CMF likely, but they have some lists of
> users associated with them.
>
> The way I'm dealing with it is to overwrite the controller, injecting
> one that extends from the ContentController and load this users in
> there, using the proposed "getParams" extension point. But it feels a
> little cumbersome.
>
> A better way would be having some kind of "proxy"in the document and be
> able to load this users on demand, navigating through the model. Any
> ideas of an easy way to do that?

you could use either a custom RouteEnhancer of the cmf dynamic router
[1], or a custom ParamConverter [2]. with both of these, you could then
expect the user list as a parameter in your controller.
if you need proxies for that, maybe Ocramius/ProxyManager [3] could be
something to use.


[1]
http://symfony.com/doc/current/cmf/components/routing/dynamic.html#route-enhancers
[2]
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
[3] https://github.com/Ocramius/ProxyManager

Bruno Reis

unread,
Aug 8, 2015, 11:48:15 AM8/8/15
to symfony-...@googlegroups.com
A followup on this, from a more experienced perspective now. 

I decided to have one entity AND one document almost every time I need a page showing something that is on the orm. I'm using the odm only for content management and the orm for all the "normal" app. I have a entity on orm and the pagefor this entity on odm. 

So, using a conference as an example. I have a conference entity that has the basic conference values. If I want a conference page to be shown, I will also Model a ConferencePage odm document. 

Of course I can reference the entity from this one, but, I might choose to replicate some data if I need also. 

This is also nice because I can have multiple pages for a same entity. 
This is feeling a lot cleaner so far. 
 
The only drawback I can foresee might happen when I need a granular page rendering a lot of child blocks and those child blocks/items all need to read data from orm.

Reply all
Reply to author
Forward
0 new messages