3
votes

I am using the Doctrine Module for ORM functionality in Zend Framework 2. I am trying to build a modular architecture based on Zend Skeletton Application which makes it possible to override and extend functionality from module A in module B. I will also have to extend entities just by plugin in a new module.

Now my problem is that the xml schema for entities is very static in module A. There is no possibility to override it with module B. I thought of implementing a service which tells the doctrine module where to find the xml schema to use for a specific entity, but thats not enough.

For example when module B extends module A but module C also extends module A - which xml schema to use - from module B or from module C ? So I want to build the xml schema dynamically from two or more schema files - one in module B and one in module C.

Which is the best way to realize such architecture ? Is it a good approach to write a Service which can be invoked from all modules to collect all xml schema files ? How to tell Doctrine to merge these files ? Is there a better way then touching the Doctrine Module - for example in a config file ?

1
Did you already consider defining a custom mapping driver? - Ocramius
Are you talking about like this: NewsItem (id,title,text) YouTubeItem (id,title,text,youtubelink) DownloadItem (id,title,text,dllink) CarItem (id,title,text,horsepower,topspeed) ? I have such a use case and i used DiscriminatorMapping to achieve this. - Sam
Hi Ocramuis! Yes, something like that was going threw my mind. I was not sure if thats the way it is supposed to do. So you think its possible to teach my custom mapping driver to merge xml files ? Is it the right way to use a service for collecting the xml schemas from multiple modules ? - ibo_s
Hi Sam! No, thats not what I need. I think you're talking of table inheritance. So you're writing a new Entity which extends the first one, but what I want is to extend the exactly same Entity with more fields. Example: Module A defines the Entity "Student". Student has id, matriculationNo, name, age. And an association to a "University". Now Module B extends the Application with more functionality and adds an association named "Address" to the "Student" entity. The module is called let's say "Address Management". - ibo_s
@user2205964 if your mapping logic is dynamic, yes. The problem is that mappings are cached, so either disable the cache (poor performance) or keep it enabled (can't change mappings at runtime reliably) - Ocramius

1 Answers

0
votes

@ibo_s no luck here. Tried to write an adapter, but that way to complicated and i got stuck pretty fast there. In the end I just duplicated some entity dcm.xml's and used configuration overriding to point to the correct one. So gave up on extending entities.