php 集合更新反面形式BUG!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 集合更新反面形式BUG!相关的知识,希望对你有一定的参考价值。

https://github.com/symfony/symfony/issues/1540

by_reference = false, to call addElement(), removeElement()

$builder->addEventListener(FormEvents::POST_BIND, function(DataEvent $event) use ($em) {
    // Inverse relationship that we have to update
    $inverse    = $event->getData();
    // All possible owning-side Entities (very expensive this way, totally a hack)
    $owners     = $em->getRepository('MyBundle:OwnerEntity')->findAll();
    // User-selected collection of owning-side Entities
    $owned      = $inverse->getOwners();

    // Iterate through all possible owners & remove the inverse Entity in question
    foreach ($owners as $owner) {
        $owner->getInverses()->removeElement($inverse);
        $em->persist($owner);
    }

    // Re-establish the inverse Entity relationship that was just previously removed
    foreach ($owned as $owner) {
        $owner->getInverses()->add($inverse);
    }

    // Yes yes, the two previous for-each loops could be done in a single pass, but I'm just typing crap up!
});

以上是关于php 集合更新反面形式BUG!的主要内容,如果未能解决你的问题,请参考以下文章

Intersect() 的反面

二代身份证复印(手机正反面拍照生成1:1复印件图像)

HTTP协议是学习PHP必学的一个阶段

php 重力Wiz //重力形式//使用条目填充表单(可选择在提交时更新条目)

禁止直接分配到相关集的反面。改为使用addresses.set()

hdoj 1829 A bug's life 种类并查集