See https://github.com/doctrine/doctrine2/issues/6072#issuecomment-363038318
Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On Thu, Feb 15, 2018 at 3:48 PM, Dennis Matveyev <[email protected]> wrote: > Consider this code: > public function getRepository() > { > return $this->getDoctrine()->getRepository(ProductPricing::class); > } > > public function getPriceObject(int $productId) > { > /** > * > * @var $priceObject ProductPricing > */ > return $this->getRepository()->findOneBy(array( > 'productId' => $productId > )); > } > > The above works great if all we have is a single entity. But how could I > extend this when I need a polymorphic entity? > i.e I have AProductPricing::class, BProductPricing::class, and so on? > > I have created the following code, but I am not certain how to proceed: > class PricingEntityFactory > { > > function __invoke(string $product): ProductPricing > { > switch (strtoupper($product)) > { > case "A": > return new AProductPricing(); > > case "B": > return new BProductPricing(); > > case "D": > return new CProductPricing(); > } > } > } > > My goal is, when I have a $product that has one of {"A", "B", "C"}, to use > Doctrine to pull the record using the entity one of AProductPricing, > BProductPricing, CProductPricing. > How? > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
