Symfony2实体之间的关系跨Bundles和多个实体管理器

时间:2016-04-06 09:24:58

标签: symfony doctrine-orm

我正在使用Symfony 2.7。我在Symfony2上关于How to Work with multiple Entity Managers and Connections的文档。我在这个网站上尝试了所有解决方案但没有成功。我总是犯同样的错误:

  

[Doctrine \ Common \ Persistence \ Mapping \ MappingException]该类   '现货\ OfferBundle \实体\发售'在配置的链中找不到   名称空间Dashboard \ ProjectBundle \ Entity

在我的项目中,我有2个捆绑包。每个捆绑包都与不同的实体经理一起使用这是我的配置文件:

    # Doctrine Configuration
doctrine:
dbal:
    default_connection:       default
    connections:
        default:
            driver:   %database2_driver%
            host:     %database2_host%
            port:     %database2_port%
            dbname:   %database2_name%
            user:     %database2_user%
            password: %database2_password%
            charset:  UTF8
        spot:
            driver:   %database3_driver%
            host:     %database3_host%
            port:     %database3_port%
            dbname:   %database3_name%
            user:     %database3_user%
            password: %database3_password%
            charset:  UTF8
orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager:   default
    entity_managers:
        default:
            connection:       default
            mappings:
                DashboardProjectBundle: ~
        spot:
            connection:       spot
            mappings:
                SpotOfferBundle: ~

我有两个实体,它们之间有捆绑关系 第一个:

namespace Dashboard\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * Project
 *
 * @ORM\Table(name="project")
 * @ORM\Entity
 */
class Project
{
     /**
     * @var Spot\OfferBundle\Entity\Offer
     *
     * @ORM\ManyToOne(targetEntity="Spot\OfferBundle\Entity\Offer", inversedBy="projects")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="offer_id", referencedColumnName="id")
     * })
     */
    private $offer;

第二个:

 namespace Spot\OfferBundle\Entity;
 use Doctrine\ORM\Mapping as ORM;

 /**
  * Offer
  *
  * @ORM\Table(name="offer")
  * @ORM\Entity(repositoryClass="Spot\OfferBundle\Entity\OfferRepository")
  */
 class Offer {
        /**
        *  
        * @ORM\OneToMany(targetEntity="Dashboard\ProjectBundle\Entity\Project", mappedBy="offer")
        */
        private $projects;

我尝试使用use语句,我检查了AppKernel和Bundles的定义。我尝试使用前导反斜杠。但是没有效果。

1 个答案:

答案 0 :(得分:-1)

确保在配置文件中设置了它:

assetic:
    ...
    bundles:        [ DashboardProjectBundle, SportOfferBundle]

<强>更新

另外,尝试像这样设置orm配置:

orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager:   default
entity_managers:
    default:
        connection:       default
        mappings:
            DashboardProjectBundle: ~
            SpotOfferBundle: ~
    spot:
        connection:       spot
        mappings:
            SpotOfferBundle: ~