steevanb / doctrine-read-only-hydrator

Add SimpleObject and ReadOnly hydrators do Doctrine.
GNU General Public License v3.0
57 stars 14 forks source link

Joined inheritance type query result not being Hydrated correctly #7

Open renatogcarvalho opened 6 years ago

renatogcarvalho commented 6 years ago

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.

renatogcarvalho commented 6 years ago

Hello folks,

Any thoughts on how we can hydrate an Entity even though it's using the Joined inheritance type in Doctrine?

habashyjr commented 6 years ago

+1 It seems to be messed up

steevanb commented 6 years ago

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.