Answer the question
In order to leave comments, you need to log in
Symfony, Doctrine, PostgreSQL. How to properly organize relationships between entities?
Good day!
Began to get acquainted with Symfony. In the process, some issues related to entities arose.
There are tables in the database:
Users ( id , login, password, ...);
Salers (id, user_id, ..., FOREIGN KEY(user_id) REFERENCES Users(id) );
Managers (id, user_id, ..., FOREIGN KEY(user_id) REFERENCES Users(id) );
Customers (id, user_id, ..., FOREIGN KEY(user_id) REFERENCES Users(id) );
Those. the "Users" table contains common fields for all users. Depending on the type, an entry is created in a linked table, where attributes that are specific to each type of user are stored.
In the ORM doc and in googled articles, the links are somehow one-sidedly considered (from those that I found, of course).
Everywhere, relationships between different entities are considered. And when using this approach, the entity classes will look like this (I don’t remember the link annotations for memory, sorry (( ):
class User
{
protected $id;
protected $login;
protected $password;
// и т.д....
}
class Saler
{
protected $id;
/**
* @OneToOne(targetEntity="User", ...)
*/
protected $user;
// и т.д....
}
$saler->user->getLogin();
class Saler extends User{...}
// $saler instanceof Saler;
$saler->getLogin(); // User-method
Answer the question
In order to leave comments, you need to log in
Is it possible to organize access to entity fields in the same way as it would be with inheritance, while storing common fields in the Users table (as it is now in the database)?
That's it - the fields of the parent entity in a separate table, in their own only individual
Class Table Inheritance
UPD: A little confused with the type of inheritance, not a single table, but a class table of course. Perhaps you figured it out, but other notes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question