M
M
MasterCopipaster2021-02-01 20:47:41
Doctrine ORM
MasterCopipaster, 2021-02-01 20:47:41

How to make EXISTS in a repository?

Guys tell me please, I want to check that the table just has an entry
something like

SELECT EXISTS(SELECT id FROM table WHERE telegam_id = 1123 and telegram_login=1 )


But even I can’t figure out how to write it in Doctrine in the repository? without making a RAW request
private function isLoginTelegram(int $telegram_id):bool
    {
        //$qb->expr()->exists($sub->getDQL()
        $sub = $this->createQueryBuilder('u')
            ->andWhere('u.telegam_id = :telegram_id')
            ->andWhere('u.telegram_login = 1')
            ->setParameter('telegram_id', $telegram_id)
            ->getDQL();
        //$this->createQueryBuilder('u')->
    }

Can you tell me? - and I also wanted to ask what would be more profitable in this case? - EXISTS or COUNT

Like if COUNT > 0 it means that something was found....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MasterCopipaster, 2021-02-02
@MasterCopipaster

In general, I was prompted in moments:

Run your query directly and use Query#getSingleScalarResult(). If id is returned - there is a record, if NoResultException is thrown - then there is no record.

I really think this is the best solution...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question