I'm trying to bind two attributes to the same column in Doctrine.
My goal is to be able to populate and find an integer column from an integer value $entity->setSomeId(3), but also be able to do it using the referenced object $entity->setSome($some) (where $some is an object)
I have tried to define my entity as such :
/** * @var Some * * @ORM\OneToOne(targetEntity="Some") * @ORM\joinColumn(name="id", referencedColumnName="other_id") */ private $someId; /** * @var integer * * @ORM\Column(name="id", type="integer", length=11, precision=0, scale=0, nullable=false, unique=true) */ private $something; It works to retrieve data, but not when I try to create an entity.
I create an entity that way :
$entity = new Entity(); $entity->setSomeId(3) $entity->getSomeId(); // = 3 $em->persist($entity); $em->flush(); Gives me the following error :
`Integrity constraint: Column id cannot be null` I guess it's because $something overrides the value of $someId somewhere.
Is it possible to do what I want to do with Doctrine ? Or should I use the referenced object only, and forget about assigning integers directly to this column ?