doctrine-read-only-hydrator
doctrine-read-only-hydrator copied to clipboard
Joined inheritance type query result not being Hydrated correctly
It looks like the Hydration doesn't work for Entities modeled on a Class Table inheritance relationship: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#class-table-inheritance.
Both SimpleObjectHydrator and ReadOnlyHydrator do not work.
Example below:
/**
* @ORM\Entity(repositoryClass="App\Repository\ScheduleRepository")
* @ORM\Table(name="schedule")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorMap({
* "schedule" = "Schedule",
* "campaign_schedule" = "CampaignSchedule"
* })
*/
class Schedule extends Base
{
}
/**
* @ORM\Entity(repositoryClass="App\Repository\CampaignScheduleRepository")
* @ORM\Table(name="campaign_schedule")
*/
class CampaignSchedule extends Schedule
{
}
Repository method (just as an example):
public function findOne() {
$queryBuilder = $this->getEntityManager()
->createQueryBuilder();
$queryBuilder
->select('cs')
->from('CampaignSchedule', 'cs');
$queryBuilder->setMaxResults(1);
$query = $queryBuilder->getQuery();
return $query->getOneOrNullResult(SimpleObjectHydrator::HYDRATOR_NAME);
}
Dump after query:
object(stdClass)#5540 (12) {
["__CLASS__"]=>
string(41) "App\Entity\CampaignSchedule"
["id:Epcvip\CoreBundle\Entity\Schedule:private"]=>
NULL
["name:Epcvip\CoreBundle\Entity\Schedule:private"]=>
NULL
}
Any thoughts?
Best Regards,
Renato.
Hello folks,
Any thoughts on how we can hydrate an Entity even though it's using the Joined inheritance type in Doctrine?
+1 It seems to be messed up
For now joined inheritance doesn't works with DoctrineReadOnlyHydrator, as it's based on Doctrine array hydrator who have a lot of problems with it.
I don't think i will try to fix it, cause to do that, i have to not use Doctrine array hydrator. And it's pretty hard to create an hydrator from scratch.