Namespace doesn't contain mapped entities in S

2019-08-14 23:05发布

I've created a new entity in src/Andrei/StatisticsBundle/Entity/Attribute/Value/ButtonVarchar.php. Here is the code for this class:

<?php

namespace Andrei\StatisticsBundle\Entity\Attribute\Value;

class ButtonVarchar
{
    protected $value;
}

and in src/Andrei/StatisticsBundle/Resources/config/doctrine/ButtonVarchar.yml I defined the following mapping information:

Andrei\StatisticsBundle\Entity\Attribute\Value\ButtonVarchar:
    type: entity
    table: button_attribute_value_varchar
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        value: 
            type: string
            length: 255
    manyToOne:
        button:
            targetEntity: Button
            inversedBy: attributeValues
            joinColumn:
                name: button_id
                referencedColumnName: id

For some reason when I run php app/console doctrine:generate:entities I get the following error:

[RuntimeException] Namespace "Andrei\StatisticsBundle\Entity\Attribute\Value" does not contain any mapped entities. 

I can't understand why is this happening. Can someone point me to the right direction? Thank you.

3条回答
Emotional °昔
2楼-- · 2019-08-14 23:38

Did you add your StatisticsBundle to Doctrine config?

eg:

doctrine:
  orm:
    auto_mapping: true
    mappings:
         AndreiStatisticsBundle: ~

You can see mapping problem in the following link:

https://github.com/symfony/symfony/pull/675

查看更多
手持菜刀,她持情操
3楼-- · 2019-08-14 23:39

It seems that your entities are separated into fine grained packages. In that case you need to specify fully qualified namespace in order for it to work.

 targetEntity: Fully\Qualified\Namespace\To\Button
查看更多
贪生不怕死
4楼-- · 2019-08-14 23:42

It may also help.

This works:

MyUniqBundle:Entity

This doesn't work:

MyUniqBundle/Entity
查看更多
登录 后发表回答