Skip to content

Conversation

@arderyp
Copy link

@arderyp arderyp commented Oct 24, 2025

@ondrejmirtes
Copy link
Member

Please add a failing test showing what kind of problem this solves.

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arderyp
Copy link
Author

arderyp commented Oct 25, 2025

And yet it doesn't work in my environment. @ondrejmirtes Thought it was because I didn't have the config right, but I did have config according to docs as noted above.

So, maybe something is off in my environment, but I have looked in vain for months. May be some issue that arrived when there is lots of abstraction, inheritance, and generics

If you have an idea let me know, but I've provided examples above

@ondrejmirtes
Copy link
Member

The OP's issue isn't "TResult is unused". His issue is "getOneOrNullResult returns mixed".

Which is by design because today we do not know the hydration mode.

@arderyp
Copy link
Author

arderyp commented Oct 25, 2025

Yeah that sounds right. My issue is mixed returns. The real ripening being discovered

@VincentLanglet
Copy link
Contributor

If you have an idea let me know, but I've provided examples above

I saw your example #700 (comment)

And I think it should work with

->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);

As explained by ondrej, currently we annot be sure about ->getOneOrNullResult(), because it rely on the default value
https://github.com/doctrine/orm/blob/4f36f0129a55aff44d474089c2c777f8544b1397/src/AbstractQuery.php#L106
but:

  • You can use your own Query with a different value
  • You can write something like
$qb->getQuery()->setHydrationMode(AbstractQuery::HYDRATE_SCALAR)->getOneOrNullResult();

I assume this would require a third template parameter on the Query stub...

@arderyp
Copy link
Author

arderyp commented Oct 25, 2025

This is very interesting. I will test this next week and get back to you!

@VincentLanglet
Copy link
Contributor

This is very interesting. I will test this next week and get back to you!

I'll try to improve this situation with #702

@arderyp
Copy link
Author

arderyp commented Oct 26, 2025

holy crap, @VincentLanglet, that solved the headache I've been working around for many months now! How silly of me to not see that option, I am so grateful that you chimed in to point me in the right direction!! If #702 is workable, it seems like a great idea, as hydrating the object seems like a logical default assumption for this package.

Thanks again, you make my week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants