简体   繁体   中英

Sonata Admin edit form many to many not working - symfony2.1.6

I am having a problem with implementing the many to many relationship in the sonata admin edit form, with the following structure.

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

I have seen many threads and have tried the solutions listed in them. I have tried

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

I get the following error

No entity manager defined for class Doctrine\ORM\PersistentCollection 

Then when i couldn't find a way to solve this, I switched to

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

I got the following error

INVALID MODE type : sonata_type_collection - mapping : 8 

I am also unable to figure out how to get and display the quantity from the purchase_product table.

Any pointers and help is highly appreciated.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM