1

I'm having troubles with a parameter in Symfony request. I have 3 entities : Mall hasMany Stores hasMany Turnovers

In my turnoverEntity, I need to get turnovers from one company. I did this :

public function findForCompany($companyId)
{   
   $qb = $this->createQueryBuilder('t')
        ->innerJoin('t.store', 's')
        ->innerJoin('s.mall', 'm')
        ->where('m.id = :companyId');

    $qb->setParameter('companyId', $companyId);

    dump($companyId);
    dump($qb->getQuery()->getSql());
    dump($qb->getQuery()->getResult());
    exit();

    return $qb->getQuery()->getResult();

}

When I dump sql I get

SELECT t0_.id AS id_0, t0_.amount AS amount_1, t0_.created_at AS created_at_2, t0_.month AS month_3, t0_.year AS year_4, t0_.is_consolidated AS is_consolidated_5, t0_.created_by AS created_by_6, t0_.store_id AS store_id_7, t0_.company_id AS company_id_8 FROM turnover t0_ INNER JOIN store s1_ ON t0_.store_id = s1_.id INNER JOIN mall m2_ ON s1_.mall_id = m2_.id WHERE m2_.id = ?

Notice the "?" at the end of the query. I get no result in my query. Did i miss something ?

EDIT :

Thanks to Kuba, the answer is just a miss in entities relationship The query should be :

$qb = $this->createQueryBuilder('t')
        ->innerJoin('t.store', 's')
        ->innerJoin('s.mall', 'm')
        ->where('m.company = :companyId');
Seb N
  • 41
  • 7
  • And when you run query - do you get results? – u_mulder Aug 30 '17 at 15:29
  • 2
    Is mall and company the same entity? If not maybe do you want to have `->where('m.companyId = :companyId');`? – kuba Aug 30 '17 at 15:33
  • Thank you Kuba, you were right. It was just a miss in my entities relationship. I blame myself... I think I need to sleep now. TY – Seb N Aug 30 '17 at 15:43
  • `$qb->getQuery()->getSql()` return the sql without parameters, if you want parameters you can use `$qb->getQuery()->getParameters()`. to see the full query, I advise you to use the symfony debug bar, in the Doctrine section, you will see all the queries sent to your database and by clicking on' View runnable query' of the desired query, you will see it completely with SQL and parameters. – doydoy44 Aug 30 '17 at 15:48
  • can you look at this two posts https://stackoverflow.com/a/11965563/7261317,https://stackoverflow.com/a/16255159/7261317 – Robert Aug 30 '17 at 16:18

0 Answers0