Merge pull request #593 from norzechowicz/hydrator-fix
Fix SimpleObjectHydrator behavior when column not exists in fieldMappings, relationMappings and metaMappings
This commit is contained in:
commit
4982e2b6b0
2 changed files with 28 additions and 1 deletions
|
@ -176,10 +176,13 @@ class SimpleObjectHydrator extends AbstractHydrator
|
||||||
// One solution is to load the association, but it might require extra efforts.
|
// One solution is to load the association, but it might require extra efforts.
|
||||||
return array('name' => $column);
|
return array('name' => $column);
|
||||||
|
|
||||||
default:
|
case (isset($this->_rsm->metaMappings[$column])):
|
||||||
return array(
|
return array(
|
||||||
'name' => $this->_rsm->metaMappings[$column]
|
'name' => $this->_rsm->metaMappings[$column]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,28 @@ class SimpleObjectHydratorTest extends HydrationTestCase
|
||||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
||||||
$hydrator->hydrateAll($stmt, $rsm);
|
$hydrator->hydrateAll($stmt, $rsm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExtraFieldInResultSetShouldBeIgnore()
|
||||||
|
{
|
||||||
|
$rsm = new ResultSetMapping;
|
||||||
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a');
|
||||||
|
$rsm->addFieldResult('a', 'a__id', 'id');
|
||||||
|
$rsm->addFieldResult('a', 'a__city', 'city');
|
||||||
|
$resultSet = array(
|
||||||
|
array(
|
||||||
|
'a__id' => '1',
|
||||||
|
'a__city' => 'Cracow',
|
||||||
|
'doctrine_rownum' => '1'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$expectedEntity = new \Doctrine\Tests\Models\CMS\CmsAddress();
|
||||||
|
$expectedEntity->id = 1;
|
||||||
|
$expectedEntity->city = 'Cracow';
|
||||||
|
|
||||||
|
$stmt = new HydratorMockStatement($resultSet);
|
||||||
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
||||||
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||||
|
$this->assertEquals($result[0], $expectedEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue