我的代码是:
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();
它工作正常,每个音符都是多个对象的数组。