Make QueryBuilder.one
return single value instead of list if only single projection
#3946
Labels
QueryBuilder.one
return single value instead of list if only single projection
#3946
When projecting a single property in a query,
one()
andfirst()
will still return a list, forcing one to still index the returned list to get the value of interest. This leads to a lot of occurrences of the following code:If there is only a single projection in the query, then the
QueryBuilder
knows that the user most likely just wants the single result and could return that instead of the pointless list. This would simplify the code toThe difference in type of the result value is acceptable, I find, because the caller defines the projections and so is guaranteed to know what the type of the return value is going to be. However, this would be a backwards incompatible change, so this could only be integrated in
v2.0.0
at the earliest.The text was updated successfully, but these errors were encountered: