Good day. I have a base entity - Place and its 2 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 contain both InPlace and OutPlace , which is why I bind with the base Place class

Actually the question is - do I sample 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 Place has no photo field (it’s correct, because photo is only in the child classes).

How can I make it so that when a sample is picked up, it’s not a base class, but a child class that is tied to this Geo ?

Coped in the direction of resolve_target_entity , but there the binding goes of one class to one

  • Maybe it's architecture? After all, if you judge, in your Geo entity, the $ place property is of the Place type, and even if you drop an object like InPlace or OutPlace there, how will you use the Geo :: getPlace () method? which will return the type Place? Are you really going to use the instanceof construction? Those. you still can not access the photos, even if they are set in the object In / OutPlace (if you act "honestly" and do not constantly resort to instanceof) - AmsTaFFix
  • I think you need to use discriminators. Example: stackoverflow.com/questions/43453036/… . Well, the doctrine dock docs.doctrine-project.org/projects/doctrine-orm/en/latest/… - mxSandr

0