使用GORM根据子表中的列进行排序? [英] Sort based on column in child table using GORM?
本文介绍了使用GORM根据子表中的列进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我想要使用GORM获取在地址表中按地址1排序的员工列表。
pre $
Employee.findAllByName(name,[max:maxRecords,offset:100,sort:Address.address1,order:desc])
以上声明不起作用,我们将不胜感激。
感谢
解决方案
尝试使用 criteria 查询就像这样...
def c = Employee.createCriteria()
def results = c.list(max:maxRecords,offset:100){
eq(name,name)
address {
order addres1,desc)
}
}
这对我有用!
另一个选项是添加默认排序顺序,例如...
class地址{
...
static mapping = {
sort address1:desc
}
}
然而,我总是喜欢按照'按需'的方式来做事情,而不是定义即使在不需要时也可以每次都进行排序。 U选择。享受!
I have a table called employee and child table address.
Now I want to get a list of employees sort by address1 in address table using GORM.
Employee.findAllByName(name, [max: maxRecords, offset: 100,sort: Address.address1, order: desc])
the above statement is not working, any suggestions would be appreciated.
Thanks
解决方案
Try using a criteria query like so...
def c = Employee.createCriteria()
def results = c.list (max: maxRecords, offset: 100) {
eq("name", name)
address {
order("addres1", "desc")
}
}
This works for me!
Another option is to add a default sort order like so...
class Address{
…
static mapping = {
sort address1:"desc"
}
}
However, I always prefer to do things as an 'as-needed' basis rather than define that sorting be done every time even when it may not be needed. U pick. Enjoy!
这篇关于使用GORM根据子表中的列进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文