Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The best way to fetch Array or Object #131

Open
4orever opened this issue Sep 5, 2016 · 1 comment
Open

The best way to fetch Array or Object #131

4orever opened this issue Sep 5, 2016 · 1 comment
Labels

Comments

@4orever
Copy link

4orever commented Sep 5, 2016

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
Copy link
Member

Using this library, you can do this:

$repository->match(Spec::eq('field_name', $value), Spec::asArray());

@peter-gribanov peter-gribanov changed the title Question: The best way to fetch Array or Object The best way to fetch Array or Object Apr 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants