試圖把預測,如:
def criteria = DomainClass.createCriteria()
def results = criteria.list {
projections{
groupProperty('parameterA')
groupProperty('parameterB')
}
}
我寫了一些測試
void test2xGroupProperty(){
def pablo = new Artist(name: 'Pablo').save()
def salvador = new Artist(name: 'Salvador').save()
new Portrait(artist: pablo, name: "Les Demoiselles d'Avignon 1", value: 10.00).save()
new Portrait(artist: pablo, name: "Les Demoiselles d'Avignon 2", value: 10.00).save()
new Portrait(artist: pablo, name: "Les Demoiselles d'Avignon 3", value: 10.00).save()
new Portrait(artist: salvador, name: "The Persistence of Memory 1", value: 20.00).save()
new Portrait(artist: salvador, name: "The Persistence of Memory 2", value: 20.00).save()
new Portrait(artist: salvador, name: "The Persistence of Memory 3", value: 20.00).save()
def artistValue = Portrait.withCriteria{
projections{
groupProperty('value')
groupProperty('artist')
}
}
assert [[10.00, pablo], [20.00, salvador]] == artistValue
}
查看更多樣本的位置: https://github.com/fabiooshiro/plastic-criteria/blob/master/src/groovy/plastic/criteria/CriteriaDocTests.groovy