Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] UniqueEntity allow boolean value for repositoryMethod parameter #60441

Copy link
Copy link
Open
@ViPErCZ

Description

@ViPErCZ
Issue body actions

Description

I have this code

#[UniqueEntity(
    fields: ['alias'],
    entityClass: ParameterValue::class,
    repositoryMethod: 'findMethod',
    identifierFieldNames: ['id' => 'id'],
)]

and the repository method could be

public function findMethodi(array $criteria): bool
{
        $entity = $this->createQueryBuilder('o')
             ->select('count(o.id)');
            ->andWhere('o.alias = :alias')
            ->setParameter('alias', $criteria['alias'])
            ->getQuery()
            ->getOneOrNullResult()
        ;

        /** @var int $count */
        $count = $qb->getQuery()->getSingleScalarResult();

        return $count > 0;
}

The idea is that I don't need to download the complete data and certainly not hydrate it.
Sometimes just a method like this with COUNT(...) and returning a boolean is enough.
What do you think? Is it OK or would you rather write a new class and your own validator? Or integrate this?
If someone approves, I'll feel free to make a pull request. But if not, I don't want to waste time.
Thank you.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.