0

I am using Zf2 and Doctrine2.

What I am trying to accomplish is to write an event subscriber that can determine which objectmanger (EntityManager/DocumentManager) is being used and dynamically map a model class to a table or document.

How would I map the model to the doctrine configuration and what driver would I use?

Can I set the table and field names dynamically in a configuration file somewhere?

Is this possible and if so, please point me in the right direction.

Here is an example:

<?php

class Model
{
     protected $id;
     protected $name;
     protected $data;
}

I would like to map this one model to both ORM\ODM with the possibilty of changing property names.

Please advise.

Jean187
  • 1
  • 1
  • 1
    Frankly this sounds like a bad idea. All mapping information is stored in doctrine's metadata (mapping information), which is not configureable by default but can be changed at runtime. What you're asking for is a complete replacement of how doctrine determines this information. With that in place, you probably would need to replace the way doctrine hydrates your objects too. Your database schema has to be prepared for dynamic propoerties as well. By then you probably have replaced most of Doctrine anyway, so writing a custom ORM might be the better choice - or a different approach. – Fge Apr 13 '16 at 17:12
  • Hello @Fge. I have managed to come up with a solution to this at https://github.com/jeandormehl/jhd-base and https://github.com/jeandormehl/jhd-session. I am concerned that this approach might be a problem but I will continue tinkering at this. Thanks – Jean187 Apr 21 '16 at 11:37

0 Answers0