php - Doctrine - FindBy on One To Many relation -
lets suppose have 'product' entity
/** * @orm\entity * @orm\table(name="es_product") */ class product extends \kdyby\doctrine\entities\baseentity { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue */ private $id; ... /** * @orm\onetomany(targetentity="productlang", mappedby="product", cascade={"all"}, indexby="iso") */ protected $contentlang; ...
and productlang entity
/** * @orm\entity * @orm\table(name="es_product_lang") */ class productlang extends \kdyby\doctrine\entities\baseentity { /** * @orm\id * @orm\manytoone(targetentity="\app\modules\cmsadmin\model\lang") */ protected $lang; /** * @orm\id * @orm\manytoone(targetentity="product", inversedby="contentlang") */ protected $product; /** * @orm\column(type="string") */ protected $name;
as can see there 1 many connection between product , productlang
the question is, there possibility use doctrine's 'findby()' method 'product' repository find products based on productlang.name?
i know can
productlangrepo->findby( [ 'product' => $product, 'name' => $name])
but need stay in productrepo, means, like
productrepo->findby( [ 'contentlang["iso"]->name' => $name ])
i think approaching wrong way. should use findby on language repo:
$language = productlangrepo->findby(array('name' => $name));
and connected products (since have 2 way connection):
$productsforlanguage = $language->getproduct() //btw since many 1 should named products not product.
then have product collection can filter. if still want go product repo side have use dql or criteria write more complex filters.
Comments
Post a Comment