jdaugherty commented on code in PR #15599:
URL: https://github.com/apache/grails-core/pull/15599#discussion_r3138988277
##########
grails-data-hibernate5/docs/src/docs/asciidoc/querying/whereQueries.adoc:
##########
@@ -262,42 +271,60 @@ Operator,Criteria Method,Description
*<=*,sizeLe,The collection size is less than or equal to
|===
-==== Query Aliases and Sorting
-If you define a query for an association an alias is automatically generated
for the query. For example the following query:
+==== Sorting
+
+Sorting with `where` queries is performed by passing `sort` and (optionally)
`order` arguments to the `list` method of a <<detachedCriteria,Detached
Criteria>>.
+
+===== Single-field Sorting
+
+To sort by a single property:
[source,groovy]
----
-def query = Pet.where {
- owner.firstName == "Fred"
+def query = Person.where {
+ firstName == "Jack"
}
+
+def results = query.list(sort: "firstName")
----
-Will generate an alias for the `owner` association such as `owner_alias_0`.
These generated aliases are fine for most cases, but are not useful if you want
to later sort or use a projection on the results. For example the following
query will fail:
+By default, sorting is ascending. You can specify the direction explicitly
using the `order` argument:
Review Comment:
It's not always clear but you can call methods from the criteria builder or
use the dsl syntax. DetachedCriterias are composable while Criterias use
closure composition to be combined. If you want static typing, the
DetachedCriteria solution is thus a better solution. So the use case is a
conversion path or you want to influence the generated query. Since those
methods are callable, you can technically reference them using the alias. I
don't mind moving this to a note or something that's called out separately, but
we should leave this in the documentation until createAlias is removed (i think
that's in hibernate 7)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]