简体   繁体   English

setVariables()多对多关系symfony2

[英]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 我说实体A和实体B之间有很多对很多的关系,我将使用嵌入的形式,以便按如下所示的实体B形式添加实体A的属性

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

When I set 'multiple' to true, everything is OK. 当我将“ multiple”设置为true时,一切正常。 But when I set it to false, I get the following error 但是当我将其设置为false时,出现以下错误

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). 像往常一样,您的EntityB类中的propertyEntityAs不是公开的(受保护的或私有的)。 So you have to write (or generate) a setter for it: setEntityAs($entityAs) 因此,您必须为其编写(或生成)setter:setEntityAs($ entityAs)

multiple true may work, as I think (not sure) it uses the addXxx Setter. 多个true可能有效,因为我认为(不确定)它使用addXxx Setter。 Proof me, if you have an addEntityAs Method in your EntityB Class? 证明我,如果您的EntityB类中有addEntityAs方法?

Buuuuut, if you have a many to many relation, why you would set multiple to false? Buuuuut,如果您具有多对多关系,为什么要将倍数设置为false?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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