doctrine2: many-to-one with non default referencedColumnName does not persist entity
- by timaschew
I'm using symfony 2.1.2 with FOSUserBundle.
I extend the User from FOS and define a many-to-one (bidirectional) association to a Customer entity. I don't want to use primary key for the association (referencedColumnName). I will use another integer uniqe column: customer_no
use FOS\UserBundle\Entity\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="t_myuser")
*/
class MyUser extends BaseUser
{
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="user")
* @ORM\JoinColumn(name="customer_no", referencedColumnName="customer_no", nullable=false)
*/
$public $customer;
}
/**
* @ORM\Entity
* @ORM\Table(name="t_customer")
*/
class Customer extends BaseEntity // provides an id (pk)
{
/**
* @ORM\Column(type="integer", unique=true, nullable=false)
*/
public $customer_no;
/**
* @ORM\OneToMany(targetEntity="MyUser", mappedBy="customer")
*/
public $user;
}
When I try to persist (via a form) a new MyUser entity with an (already in db existing and) loaded Customer entity from db, I get this error:
Notice: Undefined index: customer_no in ...\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php line 608
The schema on the db is all right.
//update:
I fix the inversedBy and mappedBy stuff, but this is not the problem.