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 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏