Dennis Matveyev
2018-02-15 14:48:21 UTC
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?
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 doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
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 doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.