Answer the question
In order to leave comments, you need to log in
How can I link to a non-ID column in Doctrine 2.5?
Good day to all. I'm developing a broken service in Symfony 3, and I'm stuck creating a relationship between two tables. The simplified scheme is as follows: two entities: Action - many records and Status - several lines.
Each Action line must be associated with one of the statuses, and this is easily done via
* @ORM\ManyToOne(targetEntity="\AppBundle\Entity\Status")
* @ORM\JoinColumn(referencedColumnName="id", nullable=false)
class Action
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="\AppBundle\Entity\Status")
* @ORM\JoinColumn(referencedColumnName="code", nullable=false)
*/
private $status;
}
class Status
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="integer", unique=true)
*/
private $code;
}
Answer the question
In order to leave comments, you need to log in
The philosophy behind the doctrine is that the database is an implementation detail, and you should design the business entities, their relationships, and their interactions. The database in this case must be completely generated.
What you want to do goes against the philosophy of Doctrine. It is impossible to organize such a connection. You can join anything with anything in queries, but no more.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question