-2

I'm making an application with Symfony2 and Doctrine and i'm facing a problem i've always wondered about but it's never been an issue until today: How to handle dynamic data?

In the application i'm developing there will be some data that might be relational and to which a relational database features might be useful and other data which the structure can be dynamic and i don't care about querying and indexing, as long as it's stored and linked to other relational data, For example:

  • A user is linked to other users through a "friendship" relation
  • A user can create documents which fields can be changed dinamically type-wise and they must be linked to the user that created them

The best way to make an example is to compare it to Drupal, where you can create your own content types and define the fields inside each content type (but all the content of a certain type all have the same data, even though it can be dinamically changed without altering the code)

I don't want to use drupal though, the application i have in mind simply would be too complicated to do with drupal (probably with -a lot- of tweaks, -a lot- of modules and some code edits, which i rather avoid, I might get a similar result with drupal, but i rather start from scratch using Symfony than bending Drupal to my will, just the thought of that gives me shivers).

Back to the question. I have started studying the problem and i was thinking about a NO-SQL solution like MongoDB, but after reading around a bit i felt like i needed some direction to which point my reasearch in particular when i ended up reading this http://www.sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/ and it scared me a bit. I haven't ended my research yet but this post really made me lose hope a bit and made me decide to ask here in advance, hoping that maybe someone has already faced this problem and found a working and well tested solution (which I'd like to use rather than making an untested one myself). The issue can be split in 2 parts:

1) Database

The solutions i came up with, with my still little knowledge, are:

  1. Relational Database (MySQL or Postgres, i'm thinking about the second since it has json support) where tables with dynamic content have a text/longtext/json (in case of Postgres) field which contain a json object containing the data
  2. Drupal-like solution where each field is mapped into a new table (I don't like it, but i'm adding it for completeness sake)
  3. Hybrid Solution: relational data in a relational database, dynamic data in a NO-SQL database with fields (say, a user_id, foreign key like) to connect the two things
  4. Full No-SQL solution: just use MongoDB (but i'd like to be reassured about the issues mentioned in the post above), or something else...i'm open to suggestions (as long as they can be used with symfony and doctrine)

2) Code

I haven't yet investigated much the code part since it will have to adapt to the database solution i'll use, but i am aware that Doctrine has an ODM to handle data from a MongoDB Database. I don't know if it's possibile to use both the ORM and ODM at the same time and make them communicate but i will look into it.
In the case of #1 it shouldn't be hard, Doctrine will create an array for the data and i'll be able to retrieve through a function.
Another issue i might have will be with forms regarding this data, but i haven't investigated about yet

I am aware about the Symfony 2 CMF project which i might get some ideas from http://cmf.symfony.com/ but after looking around a bit i felt like i needed some directions on this issue

Community
  • 1
  • 1
valepu
  • 3,136
  • 7
  • 36
  • 67

1 Answers1

1

So i kept searching and i found this: Mix of MySQL and Mongodb in an application The hstore field got my interest.
Looking further i have discovered an extension to add hstore support on Doctrine and Symfony https://github.com/intaro/hstore-extension and it looks like it's exactly what i need.

In alternative i can use JSONB (still from Postgres) which looks like a very powerful tool for dynamic models, its support is being introduced in Doctrine soon and i can wait until then

Community
  • 1
  • 1
valepu
  • 3,136
  • 7
  • 36
  • 67
  • I found these git projects that add JSONB support to doctrine 2: https://github.com/opsway/doctrine-dbal-postgresql and https://github.com/boldtrn/JsonbBundle (which comes from this question: http://stackoverflow.com/questions/29539370/doctrine-query-postgres-json-contains-json-array ) – valepu Jun 22 '15 at 12:52