简体   繁体   English

具有一对一关系的实体的Symfony2 Form Collection

[英]Symfony2 Form Collection of entities with one-to-one relation

have You met with a situation in which the form contains a collection of entities that includes a one-to-one relation? 您是否遇到过这样的情况,即表单包含一组包含一对一关系的实体?

I have entity that has many addresses and every address has one-to-one relation to other entity. 我的实体有很多地址,每个地址都与其他实体一一对应。 I have problem when displaying saved data because when I use 显示保存的数据时出现问题,因为使用时

{% for address in form.clubAddress %}
<div class="entry grid_9">
    <div class="grid_12">
        {{ form_widget(address.street) }}
        {{ form_widget(address.geoInfo.street) }}
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
</div>
{% endfor %}

it display only last geoInfo element. 它仅显示最后的geoInfo元素。

If anyone would be intrested the problem was with 如果有人会被困扰的话

form_widget()

each one-to-one element had identical id, so form_widget was displayed only once. 每个一对一的元素具有相同的ID,因此form_widget仅显示一次。 I made a macro to workaround this problem. 我做了一个宏来解决此问题。

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

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