4

I have a question regarding YAML configuration of Doctrine in Symfony2.

I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format. This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.

As an example, if I run

./app/console doctrine:schema:create

it fails, saying:

[RuntimeException]                                                 
Bundle "MySuperBundle" does not contain any mapped entities.

My automapping is already set to "true".

If I choose to use annotation config this would not be a problem.

Did I miss something? Are there any extra steps that I should take?

Thank you in advance, regards,

Ivan

frumious
  • 1,567
  • 15
  • 25
Ivancodescratch
  • 405
  • 4
  • 14
  • Did you generate the entity classes with `app/console doctrine:generate:entities MySuperBundle`? – kix Oct 01 '14 at 06:59
  • Yes, indeed i already tried that. It said that: `Bundle "MySuperBundle" does not contain any mapped entities`. – Ivancodescratch Oct 01 '14 at 07:12
  • Has the yml file with the entity information been created ? Can you find it ? – Hpatoio Oct 01 '14 at 07:26
  • Yes, it generated properly the YAML file under `../My/SuperBundle/Resouces/config/doctrine/"NameOfMyEntity".yml` as well as the PHP Entity Class under `../My/SuperBundle/Entity/"NameOfMyEntity".php – Ivancodescratch Oct 01 '14 at 07:31
  • How can i tell doctrine to use YAML as Mapping Format/ Metadata ? – Ivancodescratch Oct 01 '14 at 07:36
  • What did you mean when you said "this didn't add any metadata"? In an earlier comment you say that the YAML metadata file was in fact generated. What else were you expecting? – frumious Oct 01 '14 at 12:17

1 Answers1

6

I just had a fun time looking at the Doctrine config initialisation code. What I found was:

  • Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the type value as false
  • If type is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the order xml, yml, php
  • If it doesn't find any of those it assumes annotation

Do you have anything else at all in the Bundle/Resources/config/doctrine folder? If so, it might be throwing off the auto-detection.

That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?

It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config

doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

to explicit

doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: false
        mappings:
            MySuperBundleName:
                type: yml
                dir: Resources/config/doctrine
frumious
  • 1,567
  • 15
  • 25
  • frumious, that is excelent. Changing and adding the doctrine config as you mention it solve the problem. Thanks a lot. Where did you read all of this. I can't find it anywhere. I wish i can +1 your reputation. Maybe someone can help +1 frumious. – Ivancodescratch Oct 01 '14 at 14:01
  • No problem, it's the thought that counts! Feel free to come back when you've got a bit more rep, of course... I got the info about what config to set (and what the defaults are) from that Symfony Doctrine doc page linked in the answer, the first bit was literally from searching for "auto_mapping" in the vendor/doctrine source folder and following the code around a bit! Glad it works now. – frumious Oct 01 '14 at 16:41
  • I have the same problem with the command: 'doctrine:generate:entities XyzBundle --no-backup', and my annotations are in the XyzBundle\Entity (default) folder with the classes header annotated '@ORM\Entity', throwing this error: [RuntimeException] [RuntimeException] Bundle "XyzBundle" does not contain any mapped entities. Should I specify the directory of my vendor's bundle \Entity full path in 'dir' and 'type':'php' or anything else? Thanks in advance. – Felix Aballi Nov 11 '14 at 13:11
  • is it possible to map only one mapping file? ex. If I have Catalog/ directory with lets say 3 mapping files inside. I want only to map one specific file. Is it possible? – Jaime Sangcap Feb 05 '15 at 07:24
  • Yes, it is possible to use only 1 or more specific mapping files even if you have multiple entity managers within the same bundle. You just have to place them in a specific folder and make the necessary changes in your config file. More specifically, you have to specify the "dir" option which points to the folder where the other mappings are. For example: mappings: YourMainBundle: mapping: true type: yml dir: Resources/config/doctrine/secondMappings – Dre Feb 11 '15 at 18:34