D
D
drboboev2018-09-11 10:35:36
symfony
drboboev, 2018-09-11 10:35:36

How to create a connection between entities and a form for this connection?

Good afternoon.
There are two entities - User and Territory. Only one Territory can belong to one User, but several Users can belong to one Territory. This is clearly OneToMany, but there are a couple of "buts".
Firstly, no Territory may apply to the User at all. nullable=true and be done with it? Well, yes, as a way out of the situation it can be considered.
Secondly, I have several application fragments that somehow relate to User. Territory is one of them. Therefore, I do not want to produce the fields territory_id, blablabla_id, foo_id, bar_id, etc. in the users table. as the application grows.
From here a question - how to organize communication between User and Territory in the third table (user_to_territory for example).
I hope the question is clear.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2018-09-11
@FanatPHP

No way.
The Doctrine will make the third table for you.
And, yes, you will have to "produce". Over time, you will understand what happiness it is when all the connections are clearly spelled out in essence, and you don’t have to rush like a mad dog through the code to find how your essences relate to each other.

V
Vadim, 2018-09-12
@kylt_lichnosti

territory_id in User is normal - everyone does it, more precisely, User will simply have territory, and territory_id will already be in the database.
There is a connection through the third table, but this is for a many-to-many connection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question