2016-12-19 6 views
0

Grails Criteria Projections를 사용하여 두 열의 가능한 모든 조합을 얻고 싶습니다. 그 코드는 콜라와 COLB의 모든 반복 조합을 반환Grails 기준 투영법 - 두 속성 별 고유 투영

def criteria = { 
    projections{ 
     property('colA') 
     property('colB') 
    } 
} 

def allCombinations = MyDomainEntity.createCriteria().list(criteria) 

을하지만 :

나는 이것을 시도.

또한 distinct을 사용해 보았지만 하나의 열에서만 작동합니다.

이 문제를 해결하기위한 아이디어는 무엇입니까?

감사합니다.

답변

1

저는 실제 문제를 해결하려고하지 않고 있지만 말한 것에 따르면 groupProperty을 사용해야합니다.

// Your domain class 
class TestEntity { 
    String field1 
    String field2 
} 

// test distinct projection 
class TestEntityTest extends GroovyTestCase { 

    void testDistinctByTwoColumns() { 
     new TestEntity(field1: 'test1', field2: 'test2').save() 
     new TestEntity(field1: 'test1', field2: 'test2').save() // duplicate 
     new TestEntity(field1: 'test1', field2: 'test2').save() // duplicate 
     new TestEntity(field1: 'test3', field2: 'test4').save() 
     final result = TestEntity.withCriteria { 
      projections { 
       groupProperty('field1') 
       groupProperty('field2') 
      } 
     } 
     assertEquals(2, result.size()) 
    } 
} 

추신 : 여기

는 예제 테스트를 위해 Grails 2.5.5를 사용합니다. 어쩌면 당신의 버전은 조금 다르지만 아이디어가 분명하기를 바랍니다.

+0

나는 그것을 시험해 본다, 고마워! – NachoB