0

I'm mapping an n:m relationship and I do it as follow:

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>

Now I'm trying to validate the schema running the command Symfony > doctrine:schema:validate from Symfony2 shell and I get this error:

[Doctrine\ORM\Mapping\MappingException] The target-entity Driver\DriverBundle\Entity\Driver cannot be found in 'Device\DeviceBundle\Entity\DriverHasDevice#driver'.

Where is the problem in my mapping? I can't see it

1 Answer 1

1

Your looking for the wrong namespace. Your Driver Entity has TaxiBooking\Driver\DriverBundle\Entity namespace.

Change the Driver namespace or change the references to it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was looking on the right namespace I just forgot totally to upload new bundles to development so was my bad

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.