Symfony2使用getArrayResult没有返回正确的结果

时间:2015-12-03 16:25:36

标签: arrays symfony one-to-many query-builder

我的代码是:

return $this->repository->createQueryBuilder("z")
        ->select("absence","eleve","note")
        ->from("AppBundle:Absence", "absence")
        ->join("absence.eleve","eleve")
        ->join("eleve.notes","note")
        ->getQuery()
        ->getArrayResult();
absence.eleve是一个ManyToOne关系,eleve.notes是OneToMany RelationShip,所以经过多次体验后我注意到当我从ManyToOne转移到OneToMany时eleve.notes是一个总是包含单个对象的数组,你能不能请帮我解决一下。

这是结果的一个例子:

{"absences":
    [
        {"id":1,"column1":"***","eleve":
            {"id":38,"notes":
                [
                    {"id":131,"note":10}
                ]
            }
        },
        {"id":2,"column1":"***","eleve":
            {"id":39,"notes":
                [
                    {"id":130,"note":5}
                ]
            }
        }
    ]
}

执行此操作时:

return $this->repository->createQueryBuilder("z")
            ->select("eleve","note")
            ->from("AppBundle:Eleve", "eleve")
            ->join("eleve.notes","note")
            ->getQuery()
            ->getArrayResult();

它工作正常,每个音符都是多个对象的数组。

0 个答案:

没有答案