findBy Doctrine

Asked

Viewed 786 times

3

I would like to ask a question, I am using the command to make a filter:

$FinContaspagar = $em->getRepository(FinContaspagar::class)->findBy(array('grupo' => '0'));

However, I would like the condition from within the array to be group other than 0 (zero). I tested some PHP comparison operators to meet my condition (!=, <>), but it didn’t work. I couldn’t find anything related to this in the documentation.

Will I have to ride a DQL for that reason?

1 answer

3

EDITED

Man, in that case I’d go to createQueryBuilder.

Would be:

$qb = $em->createQueryBuilder()->from(FinContaspagar::class, 'f');

$qb->select('f');

$qb->where($qb->expr()->neq('f.grupo', $grupo));

return $qb->getQuery()->getResult();
  • I said a solution but I did not say if it is possible. As far as I know I think it is not possible to do it the way you want (I may be wrong). A while ago I also searched for a solution to solve this issue and could not find it. So I decided to use the query Builder same. If you find a solution don’t hesitate to share!

  • I took the test you forwarded, just added the ->select(f) and replaced the $group with 0 for the purpose of testing, returned no value to me... returned SELECT f FROM ModuloFinanceiro\Entities\FinContaspagar f WHERE f.grupo <> 0. Since there are several. Should I add one more condition?

  • True, I copied from a code of my own and forgot to complete it with what was missing. Mal ai! I just didn’t understand what I meant by "Since there are several". Various conditions? Something else, the return of return $qb->getQuery()->getResult(); was SELECT f FROM ModuloFinanceiro\Entities\FinContaspagar f WHERE f.grupo <> 0?

  • It worked here. If you had returned an error there, you would say to put 0(zero) in quotes because if you leave no quotes, the bank will understand that zero is a column of the table (at least it was so here).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.