Answer the question
In order to leave comments, you need to log in
How to combine entities by selecting only the required fields and save nesting?
I have a query like:
$qb = $this->createQueryBuilder("p")
->addSelect(array("u","c", "cu"))
->leftJoin("p.user", "u")
->leftJoin("p.comments", "c")
->leftJoin("c.user", "cu")
->where("p.id = :id");
$qb->setParameter("id",$id);
$query = $qb->getQuery();
return $query->getSingleResult(Query::HYDRATE_ARRAY);
Array(
'result' => Array (
"id" => "111",
"title" => "no title",
"user" => Array( "id" => "1", "email" => "1111" )
"comments" => Array ( "id" => "1", "text" => "aaaa", "user" => Array("id" => "1"));
)
);
$qb = $this->createQueryBuilder("p")
->addSelect(array("u.id","c", "cu"))
->leftJoin("p.user", "u")
->leftJoin("p.comments", "c")
->leftJoin("c.user", "cu")
->where("p.id = :id");
$qb->setParameter("id",$id);
$query = $qb->getQuery();
return $query->getSingleResult(Query::HYDRATE_ARRAY);
Array(
'result' => Array (
0 => Array(
"id" => "111",
"title" => "no title",
"comments" => Array ( "id" => "1", "text" => "aaaa", "user" => Array("id" => "1"))
),
"id" => "1"
)
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question