O
O
Oleg Kolesnikov2016-05-11 14:14:48
symfony
Oleg Kolesnikov, 2016-05-11 14:14:48

Symfony and Doctrine. How to connect 2 different child entities of the same class in a selection?

Good afternoon.
I have a base entity - Place and 2 of its children - InPlace and OutPlace
Accordingly , InPlace and OutPlace are inherited from Place .
There is also a geo object class - Geo

class Geo{

  /**
   * @ORM\ManyToOne(targetEntity="Base\Place", inversedBy="geo")
   * @ORM\JoinColumn(name="place_id", referencedColumnName="geo_id", onDelete="CASCADE")
   */
  protected $place;

}

As you can see, it can have both InPlace and OutPlace , and that's why I bind using the Place
base class. Actually, the question is - I make a selection from the database, for example, like this (Geo repository)
$qb = $em->createQueryBuilder('geo');
    $qb
      ->select('geo')
      ->leftJoin('geo.place', 'place')
      // поля photo есть только в дочерних классах. В Place их нет
      ->leftJoin('place.photo', 'photo')
    ;

and I get the corresponding error that there is no photo field in the Place class (it is correct, because photo is only in child classes). How can I make it so that when fetching, not the base class is picked up, but the child class that is attached to this Geo ? I dug in the direction of resolve_target_entity , but there the binding goes one class to one

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question