У меня есть запрос присоединиться в моем классе «Item» репозитарий объекта:Учение QueryBuilder GetResult не возвращает вложенный массив
public function findByParentItem(parentItemCodes, excludedModules) {
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('i', 'p')
->from('Bundle:ItemParent', 'p')
->join($this->getClassName(), 'i', Join::WITH, 'i.itemCode = p.itemCode')
->where(
$qb->expr()->andX(
$qb->expr()->in('p.parentItem', ':parentItem'),
$qb->expr()->notIn('i.moduleId', ':excludedModules')
)
)
->setParameter('parentItem', $parentItemCodes)
->setParameter('excludedModules', $excludedModules);
return $qb->getQuery()->getResult();
}
Item и ParentItem не связаны ассоциациями, поскольку это может указывать на другую организацию, а также.
Я ожидаю, что результат будет:
[
0 => [
0 => Item,
1 => ParentItem
],
1 => [
0 => Item,
1 => ParentItem
],
...
]
Вместо этого я получаю:
[
0 => Item,
1 => ParentItem,
2 => Item,
3 => ParentItem,
...
]
Это происходит потому, что нет никакой сущности ассоциации?
EDIT: Изменение ->from('Bundle:ParentItem', 'p', 'p.itemCode')
дает мне:
[
'ItemCode1' => ParentItem,
0 => Item,
'ItemCode2' => ParentItem,
1 => Item,
...
]
Если я:
$qb->select('i', 'p.itemCode as itemCode')
Я получаю это который больше в линиях, что я хочу:
[
0 => [
0 => ParentItem,
'itemCode' => 'ItemCode1'
],
1 => [
0 => ParentItem,
'itemCode' => 'ItemCode2'
],
...
]
EDIT: Мои объекты:
/**
* @ORM\Entity(repositoryClass="ItemRepository")
* @ORM\Table(name="item")
*/
class Item {
/**
* @ORM\Column(name="item_code", type="string", length=50)
* @ORM\Id
*/
protected $itemCode;
/**
* @ORM\Column(name="module_id", type="string", length=10, nullable=true)
*/
protected $moduleId;
// .. other properties
}
/**
* @ORM\Entity(repositoryClass="ItemParentRepository")
* @ORM\Table(name="item_parent")
*/
class ItemParent {
/**
* @ORM\Column(name="item_code", type="string", length=50)
* @ORM\Id
*/
protected $itemCode;
/**
* @ORM\Column(name="parent_item", type="string", length=50)
* @ORM\Id
*/
protected $parentItem;
}
попробовать с этим 'из()' 'функции: -> из ('Bundle: ItemParent', 'р', 'p.itemCode')' – manix
Он по-прежнему дает плоский массив, я редактировал мой вопрос. – juhah
вы также должны отправить свои сущности ... –