Answer the question
In order to leave comments, you need to log in
How correctly to organize record in a DB, the field invited?
How to properly write to the database. There is a field who invited during registration. It should display a list of names of already registered users. There is a User entity, it has first name and last name parameters. If you create another entity who invited, then which connection to choose? Who did not understand, then the problem is in the field who invited. Help a noob).
Answer the question
In order to leave comments, you need to log in
There is no need for another entity.
One-To-Many, Self-referencing
You can also set up a one-to-many association that is self-referencing. In this example we set up a hierarchy of Category objects by creating a self referencing relationship. This effectively models a hierarchy of categories and from the database perspective is known as an adjacency list approach.
class User
{
/**
* Кого пригласил
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="User", mappedBy="invitedBy")
*/
private $invitedMembers;
/**
* Кем был приглашен
* @var User
* @ORM\ManyToOne(targetEntity="User", inversedBy="invitedMembers")
*/
private $invitedBy;
public function __construct() {
$this->invitedMembers = new \Doctrine\Common\Collections\ArrayCollection();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question