Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Closed
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
1 change: 1 addition & 0 deletions grails-datastore-gorm-mongodb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PersonAttribute> {


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<AttributeContext> contexts = []
static embedded = ['contexts']
}

@Embeddable
class AttributeContext {

String id
String neighborhoodId

static belongsTo = [attribute: PersonAttribute]

}

@Service(PersonAttribute)
interface PersonAttributeDataService {
@Where({ contexts { neighborhoodId == neighborhoodId } })
List<PersonAttribute> findByNeighborhoodId(String neighborhoodId)
}