我希望在派生实例的命名查询中使用继承属性,以便可以提供自定义的结果排序。我收到一个错误。
package com.example
class Ticket {
// User is defined elsewhere
static belongsTo = [user : User]
String idNumber
}
class SeasonTicket extends Ticket {
// some custom properties go here
static namedQueries = {
locateOrderedSeasonTicketsByUser { user ->
// all derived instances are in the same table, hence return only the correct derived instances
eq("class", "com.example.SeasonTicket")
// return a match on user
user {
idEq(user.id)
}
// implement custom order
order "customProperty"
}
} << Ticket.namedQueries
}
最后一行允许使用基类中定义的任何继承的命名查询。
运行调用的集成测试时,我遇到以下错误:
SeasonTicket.locateOrderedSeasonTicketsByUser(someUserInstance)
方法com.example.User.call()的签名不适用于
参数类型:
(com.example.SseasonTicket$__clinit__closure2_closure3_closure4)
值:
[com.example.SseasonTicket$__clinit__closure2_closure3_closure4@31ee7d7a]
可能的解决方案:wait(),last(),save(),any(),getAll(),
等待(长时间)
集成测试是我第一次尝试简单测试:
void "SeasonTicket.locateOrderedSeasonTicketsByUser finds an object"() {
given:
def seasonTicket = new SeasonTicket()
def user = new User()
user.addToSeasonTickets(seasonTicket)
user.save(flush: true, failOnError: true)
expect: "we can find one season ticket"
SeasonTicket.locateOrderedSeasonTicketsByUser(user).list().size() == 1
}
看起来基类中的用户字段没有被识别。请问我做错了什么?