dqyuipw44576 2017-02-07 07:23
浏览 57
已采纳

在Symfony中使用抽象类和接口与ORM,未找到接口

I have a project which uses three different databases the first one is the main database which I can make changes to the second two belong to different projects but I need to access data in them. The following is a simplified directory structure.

Src

  • AppBundle

    • Entity
      • BusinessUnitsFox
      • DriverMax
      • VehicleFox
    • Model
      • BusinessUnitInterface
      • UDODriverInterface
      • VehicleInterface
  • FoxBundle

    • Entity
      • BusinessUnits
      • Vehicle
  • MaxBundle
    • Entity
      • DriverMax

Below are the files for the abstract class and interface for BusinessUnits the Vehicle and Driver are similar.

<?php
// src/AppBundle/Model/BusinessUnitInterface.php

namespace AppBundle\Model;

interface BusinessUnitInterface
{
    /**
     * @return string
     */
    public function __toString();
}

The Abstract Class

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FoxBundle\Entity\BusinessUnit as BaseBU;
use AppBundle\Model\BusinessUnitInterface;

 /**
  * @ORM\Entity
  * @ORM\Table(name="business_unit_fox")
  */
class BusinessUnitFox extends BaseBU implements BusinessUnitInterface
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
    * {@inheritDoc}
    * @see \AppBundle\Model\BusinessUnitInterface::__toString()
    */
    public function __toString() {
        return $this->getId();
    }
}

config.yml

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: maxdb
        connections:
            maxdb:
                # ...
            foxdb:
                # ...
            max2db:
                # ...
    orm:
        resolve_target_entities:
            AppBundle\Model\VehicleInterface: AppBundle\Entity\VehicleFox
            AppBundle\Model\UDODriver: AppBundle\Entity\DriverMax
            AppBundle\Model\BusinessUnit: AppBundle\Entity\BusinessUnitFox
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: maxem
        entity_managers:
            maxem:
                connection: maxdb
                mappings:
                    AppBundle: 
                    BWTCalendarBundle: ~
                    BWTFMBundle: ~
                    BWTHealthCheckBundle: ~
                    BWTSkytrackBundle: ~
                    BWTTelematicsBundle: ~
            foxem:
                connection: foxdb
                mappings:
                    FoxBundle: ~
            max2em:
                connection: max2db
                mappings:
                    MaxBundle: ~

When I do A SQL call I get the following error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'telematics.vehicle_fox' doesn't exist

So I ran doctrine:schema:update and got the following error

[Doctrine\Common\Persistence\Mapping\MappingException] Class 'AppBundle\Model\BusinessUnitInterface' does not exist

Is there anything that I am missing?

Is it possible to declare a OneToMany relationship from the abstract class?

  • 写回答

1条回答 默认 最新

  • dou44481 2017-02-07 08:26
    关注

    You forgot the Interface suffix for UDODriverInterface and BusinessUnitInterface. You can follow the Symfony doc to do your mapping on Abstract classes and Interfaces

    resolve_target_entities:
                AppBundle\Model\VehicleInterface: AppBundle\Entity\VehicleFox
                AppBundle\Model\UDODriverInterface: AppBundle\Entity\DriverMax
                AppBundle\Model\BusinessUnitInterface: AppBundle\Entity\BusinessUnitFox
    

    Note also with the current declaration, your AppBundle\Entity\BusinessUnitFox class is not abstract.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?