G
G
gitdev2021-02-04 17:54:34
symfony
gitdev, 2021-02-04 17:54:34

Is it correct to pass the Entity object to the repository method, or is it better to pass specific primitive values?

You need to pass Entity or concrete types to the method, as in this case. Which is more correct?

public function getSimilar(int $specializationId, int $currentId)
    {
        $v = $this
            ->createQueryBuilder('v')
            ->where('specialization_id = : specializationId')
            ->andWhere('id <> ' . $currentId)
            ->setParameters([
                'specializationId' => $specializationId,
                'id' => $currentId,
            ])
            ->orderBy('expirationDate DESC', 'bonus DESC')
            ->setMaxResults(2)
            ->getQuery()
            ->getResult();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex P., 2021-02-04
@Big_Alex

Call the repository method with entity field values ​​as arguments..

$SomeEntytyREpo->getSimilar($Entity->getId(), $Entity->getOneMoreFieldValue)

If you plan to carry out some other manipulations with the entity before making a request to the database, then it is better to move this logic into a separate service or method...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question