0

I have three Tables:

Customer CustomerUser FOS_User

I get this Error:

[Doctrine\ORM\Mapping\MappingException]
Property "id" in "FPM\AppBundle\Entity\CustomerUser" was already declared, but it must be declared only once

I don't know where is my mistake, because in the config I have

orm: auto_mapping: true

I have File CustomperUser.php

<?php

namespace FPM\AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * CustomerUser
 */
class CustomerUser
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var \Rowo\UserBundle\Entity\User
     */
    private $idUser;

    /**
     * @var \FPM\AppBundle\Entity\Customer
     */
    private $idCustomer;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set idUser
     *
     * @param \Rowo\UserBundle\Entity\User $idUser
     * @return CustomerUser
     */
    public function setIdUser(\Rowo\UserBundle\Entity\User $idUser = null)
    {
        $this->idUser = $idUser;

        return $this;
    }

    /**
     * Get idUser
     *
     * @return \Rowo\UserBundle\Entity\User
     */
    public function getIdUser()
    {
        return $this->idUser;
    }

    /**
     * Set idCustomer
     *
     * @param \FPM\AppBundle\Entity\Customer $idCustomer
     * @return CustomerUser
     */
    public function setIdCustomer(\FPM\AppBundle\Entity\Customer $idCustomer = null)
    {
        $this->idCustomer = $idCustomer;

        return $this;
    }

    /**
     * Get idCustomer
     *
     * @return \FPM\AppBundle\Entity\Customer 
     */
    public function getIdCustomer()
    {
        return $this->idCustomer;
    }
}

The File which i create during the installation of FOS_UserBundle:

<?php

namespace Rowo\UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

Here is the xml-File

<?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="FPM\AppBundle\Entity\CustomerUser" table="customer_user">
    <indexes>
      <index name="customer_user_customer_fk1_idx" columns="id_customer"/>
      <index name="customer_user_user_fk2_idx" columns="id_user"/>
    </indexes>
    <id name="id" type="integer" column="id">
      <generator strategy="IDENTITY"/>
    </id>
    <many-to-one field="id" target-entity="FosUser">
      <join-columns>
        <join-column name="id_user" referenced-column-name="id"/>
      </join-columns>
    </many-to-one>
    <many-to-one field="idCustomer" target-entity="Customer">
      <join-columns>
        <join-column name="id_customer" referenced-column-name="id"/>
      </join-columns>
    </many-to-one>
  </entity>
</doctrine-mapping>
  • Maybe `` instead of `` in the XML will resolve this? – kix Jun 03 '15 at 14:34
  • Wenn I change this, i got the error: [Doctrine\ORM\Mapping\MappingException] The target-entity FPM\AppBundle\Entity\FosUser cannot be found in 'FPM\AppBundle\Entity\CustomerUser#idUser'. –  Jun 03 '15 at 14:36
  • could that happen, because there is no orm xml from FosUser available? –  Jun 03 '15 at 15:08

1 Answers1

0

You don't need a id column for your CustomerUser table as it is the many-to-many join-table. Besides if you don't need extra columns in the CustomerUser table you don't need to create this whole entity!

You can just tell Doctrine that you want a many-to-many relation and Doctrine will automatically create your third table. Take a look here

If you still want to continue with your CustomerUser entity then take a look at this example.

Community
  • 1
  • 1
Frank B
  • 3,667
  • 1
  • 16
  • 22