Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ else if (criterion instanceof PropertyCriterion) {
Object value = pc.getValue();
if (value instanceof QueryableCriteria) {
setDetachedCriteriaValue((QueryableCriteria) value, pc);
}
// ignore Size related constraints
else {
doTypeConversionIfNeccessary(getEntity(), pc);
} else {
if (!(value instanceof DetachedCriteria)) {
doTypeConversionIfNeccessary(getEntity(), pc);
}
}
}
if (criterion instanceof DetachedAssociationCriteria) {
Expand Down Expand Up @@ -266,6 +266,7 @@ protected String getCurrentAlias() {

@SuppressWarnings("unchecked")
static void doTypeConversionIfNeccessary(PersistentEntity entity, PropertyCriterion pc) {
// ignore Size related constraints
if (pc.getClass().getSimpleName().startsWith(SIZE_CONSTRAINT_PREFIX)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DetachCriteriaSubquerySpec extends GormDatastoreSpec {

@Override
List getDomainClasses() {
return [User, Group, GroupAssignment]
return [User, Group, GroupAssignment, Organisation]
}

void "test detached associated criteria in subquery"() {
Expand Down Expand Up @@ -43,6 +43,30 @@ class DetachCriteriaSubquerySpec extends GormDatastoreSpec {
result.size() == 1
}

void "test executing detached criteria in sub-query multiple times"() {

setup:
Organisation orgA = new Organisation(name: "A")
orgA.addToUsers(email: 'user1@a')
orgA.addToUsers(email: 'user2@a')
orgA.addToUsers(email: 'user3@a')
orgA.save(flush: true)
Organisation orgB = new Organisation(name: "B")
orgB.addToUsers(email: 'user1@b')
orgB.addToUsers(email: 'user2@b')
orgB.save(flush: true)

when:
DetachedCriteria<User> criteria = User.where {
inList('organisation', Organisation.where { name == 'A' || name == 'B' }.id())
}
List<User> result = criteria.list()
result = criteria.list()

then:
result.size() == 5
}

void "test that detached criteria subquery should create implicit alias instead of using this_"() {

setup:
Expand Down Expand Up @@ -74,9 +98,11 @@ class DetachCriteriaSubquerySpec extends GormDatastoreSpec {
}

private User createUser(String email) {
User user = new User()
user.email = email
user.save(flush: true)
User user = new User(email: email)
Organisation defaultOrg = Organisation.findOrCreateByName("default")
defaultOrg.addToUsers(user)
defaultOrg.save(flush: true)
user
}

private Group createGroup(String name, User supervisor) {
Expand All @@ -99,6 +125,7 @@ class DetachCriteriaSubquerySpec extends GormDatastoreSpec {
@Entity
class User implements HibernateEntity<User> {
String email
static belongsTo = [organisation: Organisation]
static mapping = {
table 'T_USER'
}
Expand All @@ -121,3 +148,9 @@ class GroupAssignment implements HibernateEntity<GroupAssignment> {
table 'T_GROUP_ASSIGNMENT'
}
}

@Entity
class Organisation implements HibernateEntity<Organisation> {
String name
static hasMany = [users: User]
}