phpsymfonydoctrine-orm

What type of object does "getResults()" return in docrine query


When I execute query using find(id) then it works OK.
But when I use createQuery method like

select u from User u where u.id = 1 then I get error that it is an array.

So I want to know if it always returns an array even if the result is 1?

I tried getMaxResults(1) but I get the same error


Solution

  • Answer for your question can be found in documentation. It says

    The getResult() method returns an array of results. If you're querying for just one object, you can use the getSingleResult() method instead:

    You should also check this doc.