diff --git a/grails-datastore-gorm-mongodb/build.gradle b/grails-datastore-gorm-mongodb/build.gradle index d79fe5b6..61d52a14 100644 --- a/grails-datastore-gorm-mongodb/build.gradle +++ b/grails-datastore-gorm-mongodb/build.gradle @@ -14,6 +14,7 @@ dependencies { compileOnly "javax.servlet:javax.servlet-api:$servletApiVersion" testImplementation "org.grails:grails-datastore-gorm-tck:$datastoreVersion" + testImplementation "org.grails:grails-gorm-testing-support:${testingSupportVersion}" testImplementation "org.hibernate:hibernate-validator:$hibernateValidatorVersion" testImplementation "org.grails:grails-datastore-gorm-support:$datastoreVersion", { exclude group: "org.grails", module:"grails-datastore-gorm-hibernate-core" diff --git a/grails-datastore-gorm-mongodb/src/test/groovy/org/grails/datastore/gorm/mongo/EmbeddedWhereClauseSpec.groovy b/grails-datastore-gorm-mongodb/src/test/groovy/org/grails/datastore/gorm/mongo/EmbeddedWhereClauseSpec.groovy new file mode 100644 index 00000000..914e9bf7 --- /dev/null +++ b/grails-datastore-gorm-mongodb/src/test/groovy/org/grails/datastore/gorm/mongo/EmbeddedWhereClauseSpec.groovy @@ -0,0 +1,55 @@ +package org.grails.datastore.gorm.mongo + +import grails.gorm.services.Service +import grails.gorm.services.Where +import grails.gorm.tests.GormDatastoreSpec +import grails.persistence.Entity +import grails.testing.services.ServiceUnitTest + +import javax.persistence.Embeddable + +class EmbeddedWhereClauseSpec extends GormDatastoreSpec implements ServiceUnitTest { + + + void "Can construct data service where clause on embedded object"() { + given:"An object with an embedded field on it" + def attribute = new PersonAttribute(contexts: [new AttributeContext(neighborhoodId: '1234')]) + attribute.save() + + when:"We query using the autogenerated where clause" + def response = service.findByNeighborhoodId('1234') + + then:"The association is valid" + response.size() == 1 + response.first().contexts.first().neighborhoodId == '1234' + + } + + @Override + List getDomainClasses() { + [PersonAttribute] + } +} + +@Entity +class PersonAttribute { + String id + List contexts = [] + static embedded = ['contexts'] +} + +@Embeddable +class AttributeContext { + + String id + String neighborhoodId + + static belongsTo = [attribute: PersonAttribute] + +} + +@Service(PersonAttribute) +interface PersonAttributeDataService { + @Where({ contexts { neighborhoodId == neighborhoodId } }) + List findByNeighborhoodId(String neighborhoodId) +}