I have a join query in my "Item" entity repository class:
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 and ParentItem are not connected by association because it might point to another entity as well.
I expect the result to be:
[
0 => [
0 => Item,
1 => ParentItem
],
1 => [
0 => Item,
1 => ParentItem
],
...
]
Instead I get:
[
0 => Item,
1 => ParentItem,
2 => Item,
3 => ParentItem,
...
]
Is this happening because there is no entity association?
EDIT: Changing ->from('Bundle:ParentItem', 'p', 'p.itemCode')
gives me:
[
'ItemCode1' => ParentItem,
0 => Item,
'ItemCode2' => ParentItem,
1 => Item,
...
]
If I do:
$qb->select('i', 'p.itemCode as itemCode')
I get this which is more in the lines of what I want:
[
0 => [
0 => ParentItem,
'itemCode' => 'ItemCode1'
],
1 => [
0 => ParentItem,
'itemCode' => 'ItemCode2'
],
...
]
EDIT: My entities:
/**
* @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;
}