在我的项目中,我有很多平衡和笼子表之间的关系,卡是连接表,下面是我的代码
Entity/Balance
/**
* @ORM\OneToMany(targetEntity="Card", mappedBy="balance")
*/
protected $cards;
/**
* @var integer
*
* @ORM\Column(name="category_id", type="integer")
*/
protected $categories;
-----------------------------------------------------------------------
Entity/Category
/**
* @ORM\OneToMany(targetEntity="Card", mappedBy="category")
*/
protected $cards;
-----------------------------------------------------------------------
Entity/Card
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="cards")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
protected $category;
/**
* @ORM\ManyToOne(targetEntity="Balance", inversedBy="cards")
* @ORM\JoinColumn(name="balance_id", referencedColumnName="id")
*/
protected $balance;
所以当我想创建一个平衡记录时,我应该选择它属于哪个类别,所以我尝试使用表单实体类型从类别实体获取数据并将类别ID保存到Balance表(category_id)。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('value')
->add('categories', 'entity', array(
'class' => 'myBundle:Category',
'property' => 'name',
))
;
}
数据存储但category_id的值为0 ????