【问题标题】:MappingException: target entity not foundMappingException:找不到目标实体
【发布时间】:2014-07-01 14:26:59
【问题描述】:

我正在映射一个 n:m 关系,我这样做如下:

Device\DeviceBundle\Entity\DriverHasDevice.php

namespace Device\DeviceBundle\Entity;

use Driver\DriverBundle\Entity\Driver;
use Device\DeviceBundle\Entity\Device;

class DriverHasDevice
{

    protected $driver;
    protected $device;

    public function setDriver(Driver $driver)
    {
        $this->driver = $driver;
    }

    public function getDriver()
    {
        return $this->driver;
    }

    public function setDevice(Device $device)
    {
        $this->device = $device;
    }

    public function getDevice()
    {
        return $this->device;
    }

}

Device\DeviceBundle\Resources\config\doctrine\DriverHasDevice.orm.xml

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                        http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Device\DeviceBundle\Entity\DriverHasDevice" table="driver_has_device">
        <id name="driver" association-key="true" />
        <id name="device" association-key="true" />

        <many-to-one field="driver" target-entity="Driver\DriverBundle\Entity\Driver" />
        <many-to-one field="device" target-entity="Device\DeviceBundle\Entity\Device" />
    </entity>
</doctrine-mapping>

Driver\DriverBundle\Entity\Driver.php

namespace TaxiBooking\Driver\DriverBundle\Entity;


class Driver
{
    protected $id;

    protected $name;

    protected $status;


    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->firstname;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($status)
    {
        $this->status = $status;
    }
}

Driver\DriverBundle\Resources\config\doctrine\Driver.orm.xml

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Driver\DriverBundle\Entity\Driver" table="driver"
            repository-class="Driver\DriverBundle\Entity\Driver">
        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>
        <field name="name" type="string" column="name" length="50" precision="0" scale="0" nullable="true"/>
        <field name="status" type="integer" column="status" length="1" precision="0" scale="0" nullable="true"/>
        <gedmo:soft-deleteable field-name="deletedAt" time-aware="false"/>
    </entity>
</doctrine-mapping>

现在我正在尝试验证从 Symfony2 shell 运行命令 Symfony &gt; doctrine:schema:validate 的架构,我收到此错误:

[Doctrine\ORM\Mapping\MappingException] 目标实体 Driver\DriverBundle\Entity\Driver 在中找不到 'Device\DeviceBundle\Entity\DriverHasDevice#driver'。

我的映射问题出在哪里?我看不到 提前问候

【问题讨论】:

    标签: php symfony doctrine-orm doctrine


    【解决方案1】:

    您正在寻找错误的命名空间。 您的驱动程序实体具有 TaxiBooking\Driver\DriverBundle\Entity 命名空间。

    更改 Driver 命名空间或更改对它的引用。

    【讨论】:

    • 谢谢,我正在寻找正确的命名空间,但我完全忘记了将新的捆绑包上传到开发中,所以我的错
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-18
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多