我有这样一个域名...获取父数据数组列表
class Invoice {
String invoiceNo
Date invoiceDate
Date dueDate
BigDecimal totalAmount
Date sendDate
Customer customer
String fromSOorDO
static mapping = {
//formula to calculate dueDate (invoiceDate + tempo)
dueDate formula:"ADDDATE(invoice_date, tempo)"
}
static constraints = {
}
}
我需要从域invoice
所有数据传递到Array List
与parent
的名称,而不是id
。
例如,从域invoice
,我们可以看到Customer customer
。
当我们从数据库中看到,现场customer
是id
像1
,2
,3
其中属于表Customer
。
这是客户的域名。
class Customer {
String code
String name
String address
String phoneNo
static constraints = {}
}
我需要将所有数据通过发票成ArrayList
其中Customer
的id
替换Customer
的name
..
实施例的数据:
表invoice
具有customer = 1
然后表客户这样:
id | code | name | address| phoneNo|
1 | A |aaaaaa| Street |123132 |
2 | B |bbbbbb| Street |454545 |
当我检索域invoice
与customer
的字段显示为客户的名称并将其填充到哈希映射。
def invoice = c.list(params) {
ge("invoiceDate", dateFrom)
eq("deleteFlag", "N")
eq("cif", cif)
}
def map = new HashMap()
map.put("invoiceList",invoice)
我试图用collect
喜欢这一点,并得到这个错误:
def c = Invoice.createCriteria()
def invoice = c.list(params) {
ge("invoiceDate", dateFrom)
eq("deleteFlag", "N")
eq("cif", cif)
}.collect{ invoice ->
invoice.properties.collect{ it } + [customer:invoice.customer.name]
}
ERROR org.grails.web.errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [POST] /api/listofinvoice/index - parameters:
lastupdate: 01/01/2016
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional one here. Stacktrace follows:
java.lang.IllegalStateException: No Datastore Session bound to thread, and configuration does not allow creation of non-transactional one here
at grails.beans.util.LazyMetaPropertyMap.entrySet(LazyMetaPropertyMap.java:224) ~[grails-core-3.1.1.jar:3.1.1]
at com.vastpalaso.market.InvoiceController$_closure14$_closure23$$EQ4ZWTHZ.doCall(InvoiceController.groovy:607) ~[na:na]
at com.vastpalaso.market.InvoiceController$_closure14$$EQ4ZWTHV.doCall(InvoiceController.groovy:602) ~[na:na]
at grails.plugin.springsecurity.web.UpdateRequestContextHolderExceptionTranslationFilter.doFilter(UpdateRequestContextHolderExceptionTranslationFilter.groovy:64) ~[spring-security-core-3.1.1.jar:na]
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53) ~[spring-security-core-3.1.1.jar:na]
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62) ~[spring-security-core-3.1.1.jar:na]
at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58) ~[spring-security-core-3.1.1.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_111]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
你真的认为我们需要查看您的域类的所有属性?包括那些,评论一些巨型巨无霸? – injecteer
@injecteer完成 – akiong