[DDC-1492] Fatall error: Cannot use object as array in ORM\Internal\Hydration\ObjectHydrator.php on line 314 Created: 13/Nov/11  Updated: 15/Nov/11  Resolved: 15/Nov/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.1.1
Fix Version/s: 2.2
Security Level: All

Type: Bug Priority: Blocker
Reporter: Konstantin Assignee: Guilherme Blanco
Resolution: Fixed Votes: 0
Labels: None
Environment:

Symfony2, Doctrine 2.1.1 (also bug present on 2.1.3-dev - latest revison of 2.1.x branch)



 Description   

My entities

event
eveht.event_area_id=event_area.id (1:1)
event_area.event_id=event.id (1:1)
event_area.area.id=area.id (one area has many event_area's)
area.parent_id=area_id (hierarchial)
event.author_id=user.id (one user has many events)

area - STI: District/City/Region/Country/etc.

SELECT
	r, ra, a, ap, au, DATE(r.eventTime) AS event_date
FROM OloloEventsBundle:Event r
	LEFT JOIN r.eventArea ra
		LEFT JOIN ra.area a
			LEFT JOIN a.parent ap
	INNER JOIN r.author au WHERE r.eventTime <= :r_eventtime AND ra.area IN(:ra_area)
GROUP BY r
ORDER BY event_date DESC

This DQL caused an error "Cannot use object of type District as array in ORM\Internal\Hydration\ObjectHydrator.php on line 314". When I'm removing `ap` friom fetching - it works. Mapping are correct - there are many other places where it works correctly.



 Comments   
Comment by Benjamin Eberlei [ 13/Nov/11 ]

On 2.1.1 line 314 is a "}". Can you restate the line and add a stack trace if possible (xdebug or phpunit can help there).

Comment by Konstantin [ 13/Nov/11 ]

Sorry, line was changed cause I've updated to 2.1.3-dev.

( ! ) Fatal error: Cannot use object of type Ololo\Bundle\TerritorialBundle\Entity\District as array in Z:\home\dev\Ololo\code\vendors\Doctrine\Orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 308
Call Stack
#	Time	Memory	Function	Location
1	0.0006	333520	{main}( )	..\index_dev.php:0
2	0.0254	1435584	Symfony\Component\HttpKernel\Kernel->handle( )	..\index_dev.php:20
3	0.2454	3634168	Symfony\Bundle\FrameworkBundle\HttpKernel->handle( )	..\Kernel.php:171
4	0.2454	3634576	Symfony\Component\HttpKernel\HttpKernel->handle( )	..\HttpKernel.php:44
5	0.2454	3634576	Symfony\Component\HttpKernel\HttpKernel->handleRaw( )	..\HttpKernel.php:71
6	0.3589	5534264	call_user_func_array ( )	..\HttpKernel.php:117
7	0.3590	5534448	Ololo\Bundle\DistrictsBundle\Controller\DistrictController->EventsPastAction( )	..\HttpKernel.php:0
8	1.1606	13782464	Ololo\Bundle\EventsBundle\Entity\EventRepository->getPastEventsByAreasIds( )	..\DistrictController.php:145
9	1.1607	13783520	Ololo\Bundle\EventsBundle\Entity\EventRepository->getEventsSliceBySpecification( )	..\EventRepository.php:385
10	1.2010	14224216	Doctrine\ORM\AbstractQuery->getResult( )	..\EventRepository.php:477
11	1.2010	14224368	Doctrine\ORM\AbstractQuery->execute( )	..\AbstractQuery.php:392
12	3.3409	14781264	Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll( )	..\AbstractQuery.php:594
13	3.3412	14785824	Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateAll( )	..\AbstractHydrator.php:99
14	3.3413	14798576	Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateRow( )	..\ObjectHydrator.php:140
                    $parentObject = $this->_resultPointers[$parentAlias][key($first)]; // trouble here, $this->_resultPointers[$parentAlias] is object of District
Comment by Guilherme Blanco [ 14/Nov/11 ]

Hi.

If you change this line:

$parentObject = $this->_resultPointers[$parentAlias][key($first)];

To this:

$parentObject = $first[key($first)];

Does it work for you?

Comment by Konstantin [ 14/Nov/11 ]

yes, with this line of code this query works.

Comment by Guilherme Blanco [ 15/Nov/11 ]

https://github.com/doctrine/doctrine2/commit/77e076f1fdbe24fdb2f5a1fb1842c0b9cb7d95a4

This issue was fixed in master.
I requested Benjamin to merge this with 2.1 branch.

Thanks

Generated at Wed Oct 22 05:06:41 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.