我在使用以下结构的奏鸣曲管理编辑表单中实现多对多关系时遇到问题。
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 表中获取和显示数量。
任何指示和帮助都非常感谢。
最佳答案
您可以尝试添加 'expanded' => true 和 'multiple' => true
->add('products', 'sonata_type_model', array('expanded' => true, 'by_reference' => false, 'multiple' => true))
关于symfony - Sonata Admin 编辑表单多对多不起作用 - symfony2.1.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14286471/