简体   繁体   中英

setVariables() many to many relation symfony2

I have a many to many relation between let's say entityA and entityB and I will use embeeded forms in order to add the attribute of entityA in the form of entityB as follows

$builder ->add('entityAs', 'entity', array(
              'class'    => 'xxxBundle:EntityA',
              'property' => 'name',
              'multiple' => false,
            ));}

When I set 'multiple' to true, everything is OK. But when I set it to false, I get the following error

Property "entityAs" is not public in class "xxx\Entity\EntityB". Maybe you should create the method "setEntityAs()"?

As usual the property entityAs in your EntityB class is not public (protected or private). So you have to write (or generate) a setter for it: setEntityAs($entityAs)

multiple true may work, as I think (not sure) it uses the addXxx Setter. Proof me, if you have an addEntityAs Method in your EntityB Class?

Buuuuut, if you have a many to many relation, why you would set multiple to false?

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