Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joined inheritance type query result not being Hydrated correctly #7

Open
renatogcarvalho opened this issue Mar 14, 2018 · 3 comments

Comments

@renatogcarvalho
Copy link

renatogcarvalho commented Mar 14, 2018

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
Copy link
Author

Hello folks,

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

@habashyjr
Copy link

+1 It seems to be messed up

@steevanb
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants