1

I have two document manager dm1 and dm2, and a bundle called AcmeBundle, in the bundle, i have quite a few classes, some start with "FirstClass" and some start with "SecondClass" and some other classes. For example i have

FirstClass1.php,

FirstClass2.php,

SecondClass1.php,

SecondClass2.php

Random.php

What i need is the classes start with "FirstClass" and "SecondClass" managed by both dm1 and dm2, and other classes managed only by dm1

I tried using prifix

    dm1:
         connection: dm1
         ...
         auto_mapping: false
         mappings:
             MyAcmeBundle: ~

     dm2:
         connection: dm2
         ...
         auto_mapping: false
         mappings:
             MyAcmeBundle:
                 prefix: My\AcmeBundle\Document\FirstClass

but it only works for one prefix, if I add another one it won't work. Any one know how to do this?

user2810081
  • 589
  • 1
  • 8
  • 27

1 Answers1

0

You can define several mappings for your document manager, each one with a different prefix:

dm2:
     connection: dm2
     ...
     auto_mapping: false
     mappings:
         FirstClasses:
             prefix: My\AcmeBundle\Document\FirstClass
         SecondClasses:
             prefix: My\AcmeBundle\Document\SecondClass

Downside is that if you're using Bundle:DocumentName notation you need to remember the correct prefix however Doctrine works perfectly fine with DocumentName::class which is (in my opinion) cleaner and better supported by PHPStorm for instance.

malarzm
  • 2,831
  • 2
  • 15
  • 25
  • sorry i don't quite understand, shouldn't we use bundle name under mapping? I tried this way and it saids "bundle 'FirstClasses' does not exists or is not enabled" – user2810081 May 08 '16 at 20:39
  • Can you try explictly adding `dir` keys? to mappings? I'm using such configuration and it works just fine :) – malarzm May 09 '16 at 06:14