i have a sports tournament database schema like this
here the doman
has one to many
relatinship with tournament
, i have a domain
form which collects the domain details and stores it in the database, i have the tournament and domain table like this
tournament table
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| domain_id | int(11) | YES | MUL | NULL | |
| description | longtext | NO | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
Domain Table
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| subdomain | varchar(255) | NO | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
i have a tournamentType
which collects the details of the tournament, but when submited there will obviously be a null
value for the domain_id
. how do i set the domain value for all tournaments
that will be created to lets say domain_id = 1
.
i could do it in the controller using the setters but that would be messy, is there a way to set the one
side from the many
side in the symfony embedded forms,
edit: right now i'm doing this, inside the controller
$tournament->setDomain($em->getRepository("CricketBundle\Model\Entity\Domain")->findOneById(1));
$em->persist($tournament);
$em->flush();
and inside tournament entity's setter
public function setDomain(\CricketBundle\Model\Entity\Domain $domain = null)
{
$domain->addTournament($this);
$this->domain = $domain;
return $this;
}
every thing works great, i just dont want to use the setter inside the controller, i want to move it somewhere else