我有2個實體:保存嵌入式收藏
Game
Batting
一個遊戲還有其他幾個特性,date
,location
等 一個博弈有幾個Batting
entites的,即板球 的遊戲擊球有幾種特性,Runs, Dismissal, Player
Game.php
/**
*
* @ORM\OneToMany(targetEntity="Batting", mappedBy="game", cascade={"persist", "remove"})
*/
private $battings;
/**
* Add battings
*
* @param \CW\CricketBundle\Entity\Batting $battings
* @return Game
*/
public function addBatting(\CW\CricketBundle\Entity\Batting $battings)
{
$this->battings[] = $battings;
return $this;
}
Batting.php
/**
* @ORM\ManyToOne(targetEntity="CW\CricketBundle\Entity\Game", inversedBy="battings", cascade={"persist"})
* @ORM\JoinColumn(name="game_id", referencedColumnName="id")
*/
private $game;
GameAdmin.php
->with("Batting")
->add('battings', 'sonata_type_collection', array(), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'id',
))
你可以看到這是什麼樣像下面
的prblem添加Batting
和保存Game
是什麼時候。
我期望game_id
保存在擊球數據庫表中,但它始終爲NULL。
任何想法我的代碼有什麼問題?
感謝
編輯:
更改代碼:
public function addBatting(\CW\CricketBundle\Entity\Batting $battings)
{
$battings->setGame($this);
$this->battings[] = $battings;
return $this;
}
和
public function setGame(\CW\CricketBundle\Entity\Game $game)
{
$this->game = $game;
return $this;
}
也許我的問題(和答案)可以幫助你:http://stackoverflow.com/questions/15629225/symfony2-1m-11-relationship-and-sonata-admin-form/15974241#15974241 –