W pewnym miejscu strony potrzebuję stworzyć playera który rozszerza tworzony jest na podstawie usera, player ma w sobie jeszcze kilka relacji i nie wiem jak to ogarnąć najkrócej, mój jedyny poprawny ale długi sposób to taki:
if( $player === null ){
$create = new Player();
$create->setUser( $user );
$em->persist( $create );
$em->flush();
$resources = new Resources();
$army = new Army();
$playerDataInfo = new PlayerDataInfo();
$builds = new Builds();
$research = new Research();
$resources->setPlayer( $create );
$army->setPlayer( $create );
$playerDataInfo->setPlayer( $create );
$builds->setPlayer( $create );
$research->setPlayer( $create );
$em->persist( $resources );
$em->persist( $army );
$em->persist( $playerDataInfo );
$em->persist( $builds );
$em->persist( $research );
$em->flush();
$create->setResources( $resources )
->setResearch( $research )
->setPlayerDataInfo( $playerDataInfo )
->setArmy( $army )
->setBuilds( $builds );
$user->setPlayer( $create );
$em->persist( $create );
$em->persist( $user );
$em->flush();
return $this->redirectToRoute('game_router');
}
przykład encji playera:
class Player
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="User", mappedBy="player", cascade={"all"})
*/
protected $user;
/**
* @ORM\OneToOne(targetEntity="Resources", mappedBy="player", cascade={"all"})
*/
protected $resources;
//...
przykład encji builds
class Builds
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="Player", inversedBy="builds")
* @ORM\JoinColumn(name="player_id", referencedColumnName="id")
*/
protected $player;
/**
* @ORM\Column(type="integer")
*/
protected $casement = 1;
//....
Relacje:
http://imageshack.com/a/img633/6143/3V65h5.png