我有两个这样的Doctrine查询:
FetchBookRepository:
public function fetchBook($id)
{
try {
$book = $this->em->getRepository('BooksApiBookBundle:BooksEntity')
->find($id);
var_dump($book);die();
} catch (\Exception $ex) {
$this->em->close();
throw new QueryException('003', 502);
}
return $book;
}
FetchAllBooksRepository:
public function allBooks()
{
try {
$book = $this->em->getRepository('BooksApiBookBundle:BooksEntity')
->findAll();
var_dump($book);die();
} catch (\Exception $ex) {
$this->em->close();
throw new QueryException('003', 502);
}
return $book;
}
它们都按预期工作,但是当我仔细研究返回的数据时,我注意到FetchBookRepository返回Object而FetchAllBooksRepository返回Objects数组。
为什么会发生这种情况,返回依赖于什么?是否有办法使收益标准化......?