Skip to content

The best way to fetch Array or Object #131

@4orever

Description

@4orever

Maybe it's not about this library but I'll ask. What is the best way to make repository methods to be possible to return both Array and Objects?
It's not a good idea to make two versions of one method (findBy() and findByAsArray()).

The second way I used before is bad too. I used setFetchMode() for the whole repository. It causes the promblems with unknown method result without knowing the context, IDE autocomplete and so on.

May be I just should use return $qb->getQuery() and then calls proper method in service or controller class?

$repository->findBy(/*...*/)->getArrayResult();

How to name such methods? findX() seems inappropriate.

Any other ideas?

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