You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a possibility to support array hydration type infering when field list is selected? I can see it actually works, but is not supported for getArrayResult nor ->getResult(AbstractQuery::HYDRATE_ARRAY) even though the behaviour in doctrine is equal.
Unfortunately, supporting more than one hydration mode is challenging for the reasons detailed here. So for now phpstan-doctrine supports only the HYDRATE_OBJECT mode.
As you pointed out, selecting individual fields is supported in HYDRATE_OBJECT mode, so in some cases it may be possible to use getResult() instead of getArrayResult():
$query = $em->createQuery('
SELECT e.foo, e.bar FROM Entity e
');
$query->getResult(); // array<array{foo: string, bar: string}>
Sidenote: Sad to hear that using (semantically) improper HYDRATE_OBJECT in those cases (it cannot hydrate objects when custom fields are selected) is the only working approach, but I think the benefits of type-inference is huge enough to convert our codebase to use that and write some phpstan rule to ensure that it in future.
Is there a possibility to support array hydration type infering when field list is selected? I can see it actually works, but is not supported for
getArrayResult
nor->getResult(AbstractQuery::HYDRATE_ARRAY)
even though the behaviour in doctrine is equal.I can send failing tests if needed.
cc @arnaud-lb
The text was updated successfully, but these errors were encountered: