奏鸣曲管理员编辑表格多对多不起作用 - symfony2.1.6

时间:2013-01-11 20:55:11

标签: symfony many-to-many sonata-admin

我在奏鸣曲管理编辑表单中实现多对多关系时遇到问题,具有以下结构。

purchase (id, total_price, discount, created_at)
purchase_product (purchase_id, product_id, quantity)
product (id, title, desc, price, thumbnail, created_at)

我见过很多线程,并尝试过其中列出的解决方案。我试过了

->add('products', 'sonata_type_model', array('by_reference' => false))

我收到以下错误

No entity manager defined for class Doctrine\ORM\PersistentCollection 

然后,当我找不到解决方法时,我切换到

->add('products', 'sonata_type_collection', array(), array('edit' => 'inline', 'inline' => 'table')

我收到以下错误

INVALID MODE type : sonata_type_collection - mapping : 8 

我也无法弄清楚如何从purchase_product表中获取和显示数量。

非常感谢任何指示和帮助。

1 个答案:

答案 0 :(得分:14)

您可以尝试添加'expanded'=> true和'multiple'=>真

->add('products', 'sonata_type_model', array('expanded' => true, 'by_reference' => false, 'multiple' => true))