I'm trying to do the following :
/**
* @Entity
*/
class Player {
/**
*@Column
*@Id
*/
private $uuid; //gets assigned a Uuid in the constructor
/**
* @ManyToOne(targetEntity="Team", cascade={"persist"})
* @JoinColumn(referencedColumnName="uuid")
*/
private $team;
public function setTeam(Team $team) {
$this->team = $team;
}
//...
}
/**
* @Entity
*/
class Team {
/**
* @Column
* @Id
*/
private $uuid; //gets assigned a Uuid in the constructor
//...
}
$player = new Player;
$team = new Team;
$player->setTeam($team);
$entityManager->persist($player);
$entityManager->flush();
The team is not persisted in to the database.
I do not want to call $entityManager->persist($team)
as in my case, the Team is created in a part of the code where I don't have knowledge of persistence.
My expectation is that the cascade={"persist"}
option should make the EntityManager also persist the Team. Why is my expectation wrong or what am I doing wrong?
I was not mistaken... This works as expected!
Taking a second look, there was never a flush after a added the Team to the Player.
Reading my own question again, I realised what that I missed it...
I should talk to my rubber duck more often, so it seems...