symfony - How can make a INNER JOIN in a DQL sentence? -
i have problem dql in symfony2 project. have defined 3 entities:
- a entity called category 2 fields : id , slug
- a entity called subcategory 2 fields : id , slug
- a entity called categorysubcategories 2 fields : category , subcategory
i need obtain subcatgories category (slug) given. got next dql :
$em ->createquery('select subcat subcategory subcat subcat.id in (select identity(csc.subcategory) categorysubcategories csc csc.category in (select cat category cat cat.slug = :category))') ->setparameter('category', $category);
is there anyway build dql inner joins ?
in mysql example:
select subcat.slug category cat inner join categorysubcategories csc on (cat.id = csc.category_id) inner join subcategory subcat on (csc.subcategory_id = subcat.id) cat.slug "$category"
is there anyway translate dql ?
in own opinion, there no need have third entity, 2 enough (category , subcategory) , add association manytoone between subcategory , category, described here: http://docs.doctrine-project.org/en/2.1/reference/association-mapping.html
Comments
Post a Comment