The best way to fetch Array or Object
4orever opened this issue · 1 comments
4orever commented
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?
peter-gribanov commented
Using this library, you can do this:
$repository->match(Spec::eq('field_name', $value), Spec::asArray());