public function testShouldUseEagerLoadingAndDetectBelongsToDeep()
{
$rawly = Manufacturer::findFirstById(1);
$rawly->robots = $this->resultSetToEagerLoadingEquivalent($rawly->robots);
foreach ($rawly->robots as $robot) {
$robot->parent;
}
$eagerly = Loader::fromModel(Manufacturer::findFirstById(1), 'Robots.Parent');
$this->assertTrue(property_exists($eagerly->robots[0], 'parent'));
$this->assertNull($eagerly->robots[0]->parent);
$this->assertInstanceOf('Phalcon\\Test\\Mvc\\Model\\EagerLoading\\Stubs\\Robot', $eagerly->robots[2]->parent);
$getIds = function ($obj) {
return property_exists($obj, 'parent') && isset($obj->parent) ? $obj->parent->readAttribute('id') : null;
};
$this->assertEquals(array_map($getIds, $eagerly->robots), array_map($getIds, $rawly->robots));
}