Grails Projections不会返回所有属性,也不会分组 [英] Grails Projections not returning all properties and not grouped
问题描述
如何获得它,所以我返回从下面的所有预测
def c = Company.createCriteria()
def a = c.list(params){
projection {
property'id',property'name'
}
}
if(a.size()== 0)
render404
else {
render(contentType:'text / json'){
totalCount = a.totalCount
data = a
}
}
这:
$ b {totalCount:2,data:[company1,company2]}
在哪里我需要它:
{totalCount:2,data:[{class:org.example.Company, id:1,name:company1},{class:org.example.Company,id:2,name:company2}]}
在公司领域,我有很多关系(一对一,一对多等)。
我的域名如下所示:
package org.example
import java.sql 。时间戳
class公司{
字符串名称
字符串abn
字符串cname
字符串电子邮件
字符串电话
字符串位置
字符串地址
字符串城市
字符串邮政编码
诠释风格
int openbookings;
日期日期;
int tokenTotal = 0
int totaltokens
int totalboosts
int totalposts
时间戳tokenstamp
static hasMany = [users:User,broadcast:Broadcast,bookings:Booking,locations:Location,vimsurvey:VimSurvey,rewards:Reward,tokens:CompanyToken]
static constraints = {
abn nullable:true
date date:true
style nullable:true
}
}
任何帮助都会很棒:)
????
< a href =http://grails.org/doc/1.1/ref/Domain%20Classes/createCriteria.html =nofollow> http://grails.org/doc/1.1/ref/Domain%20Classes/ createCriteria.html
请参阅投影下的属性部分:'属性返回返回结果中的给定属性'。我并没有真正明白你所要求的'所有预测'。
你是否只是想为你的域名找到全部?为什么使用投影?
def a = c.list(params){
projection {
property'id',property'name'
}
}
should
$ b
def a = c.list(params){
projection {
property'id'
property'name'
}
}
事实上,我当我尝试按照自己的方式进行操作时遇到编译错误。我仍然觉得只要获得整个域名本身就更有意义,除非有一个非常具体的原因。
How to get it so i return all of the projections from the below
def c = Company.createCriteria()
def a = c.list(params){
projections{
property 'id', property 'name'
}
}
if(a.size() == 0)
render "404"
else {
render (contentType: 'text/json'){
totalCount = a.totalCount
data = a
}
}
The result comes out like this:
{"totalCount":2,"data":["company1","company2"]}
Where i need it to be:
{"totalCount":2,"data":[{"class":"org.example.Company","id":1,"name":"company1"},{"class":"org.example.Company","id":2,"name":"company2"}]}
In the company domain i have lots of relationships (some one to one, one to many etc...) my domain looks like the following:
package org.example
import java.sql.Timestamp
class Company {
String name
String abn
String cname
String email
String phone
String position
String address
String city
String postcode
int style
int openbookings;
Date date;
int tokenTotal = 0
int totaltokens
int totalboosts
int totalposts
Timestamp tokenstamp
static hasMany = [users: User, broadcast: Broadcast, bookings: Booking, locations: Location,vimsurvey:VimSurvey,rewards: Reward, tokens: CompanyToken]
static constraints = {
abn nullable: true
date nullable: true
style nullable: true
}
}
Any help would be great:) ????
http://grails.org/doc/1.1/ref/Domain%20Classes/createCriteria.html
See the property section under projections: 'property Returns the given property in the returned results'. I don't really get what you are asking for by 'all the projections'.
Are you simply looking to Find all for your domain? Why are you using a projection?
def a = c.list(params){
projections{
property 'id', property 'name'
}
}
should be
def a = c.list(params){
projections{
property 'id'
property 'name'
}
}
In fact, I get a compilation error when I attempt to do it your way. I still feel like it makes more sense to simply get the entire domain itself unless there is a very specific reason not to.
这篇关于Grails Projections不会返回所有属性,也不会分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!