First of all, I apologize for my little knowledge of the sector, but I am new to Symfony and PHP. I am doing a new project using Symfony 4 and the following problem arises.
I have two tables in my application, one for Contracting and another for Alerts. They are related to each other through an intermediate table, since a contract can have several alerts at the same time. I leave an image so you can see the relationship.
I already have all the entities created with their Setters and Getters and all the forms made and working, to add a new alert and a new contract and all the additional functionality. My purpose is to program a function, so that in the intermediate table are stored the IDs of contracts and alerts and are related to each other so that later I can show a list of contracts with their respective alerts.
I can not create the logic to collect the contract ID and the ID of the alert and save it in the table that relates them and then shows it.
I do not know if I've explained myself correctly or if I say some nonsense, excuse me.
First of all, please read the Doctrine2 Many-to-Many docs carefully. After proper relations configuration creating relations with Doctrine
will be as easy as:
$contact->addAllert($alert);
With proper flushing if you don't have cascade: persist
configured.
You don't have to take care about the joining table - Doctrine2
will take care of it for you.