public function testShouldUseEagerLoadingAndDetectHasMany()
{
$rawly = Manufacturer::findFirstById(1);
$rawly->robots;
$eagerly = Loader::fromModel(Manufacturer::findFirstById(1), 'Robots');
$this->assertTrue(property_exists($eagerly, 'robots'));
$this->assertTrue(is_array($eagerly->robots));
$this->assertSame(count($eagerly->robots), $rawly->robots->count());
$getIds = function ($arr) {
$ret = [];
foreach ($arr as $r) {
if (is_object($r)) {
$ret[] = $r->readAttribute('id');
}
}
return $ret;
};
$this->assertEquals($getIds($this->resultSetToEagerLoadingEquivalent($rawly->robots)), $getIds($eagerly->robots));
}