I'm trying to fetch some data using two nested queries through two doctrine repos:
$user = $this->_objectManager->getRepository('\Application\Entity\User')->
findOneBy(array("hash" => $data));
$id_user = $user->getId();
$user_credits = $this->_objectManager->getRepository('\Application\Entity\UserCredits')->
findOneBy(array("user_id" => $id_user));
return $user_credits;
I apply some Hydrators in the module.config.php:
'Application\\Entity\\User' => array(
'entity_identifier_name' => 'id',
'route_name' => 'client-api.rest.getcredits',
'route_identifier_name' => 'getcredits_id',
'hydrator' => 'Zend\\Stdlib\\Hydrator\\ArraySerializable',
),
'Application\\Entity\\UserCredits' => array(
'entity_identifier_name' => 'credits',
'route_name' => 'client-api.rest.getcredits',
'route_identifier_name' => 'getcredits_id',
'hydrator' => 'Zend\\Stdlib\\Hydrator\\ArraySerializable',
),
And in each doctrine Entity I configure the getArrayCopy() like this:
User:
public function getArrayCopy()
{
return array(
'id'=>$this->getId(),
'phone'=>$this->getPhone(),
);
}
UserCredits:
public function getArrayCopy()
{
return array(
'id'=>$this->getUser(),
'credits'=>$this->getCredits(),
);
}
And here is the result:
{"credits":100,"_embedded":{"id":{"id":10,"phone":123456789,"_links":{"self":{"href":"http:\/\/testserver.test\/getcredits\/10"}}}},"_links":{"self":{"href":"http:\/\/testserver.test\/getcredits\/100"}}}
But I actually would like a result something like:
{"credits":100,"id":10},"_links":......
How can I make this possible? Why ID is embedding into it?