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
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
Expand Up @@ -375,16 +375,23 @@ public PersistentEntity createEmbeddedEntity(Class type) {

class DocumentEmbeddedPersistentEntity extends EmbeddedPersistentEntity {

private DocumentCollectionMapping classMapping ;
private DocumentCollectionMapping classMapping;

public DocumentEmbeddedPersistentEntity(Class type, MappingContext ctx) {
super(type, ctx);
classMapping = new DocumentCollectionMapping(this, ctx);
}

@Override
public boolean isIdentityName(String propertyName) {
return false;
}

@Override
public ClassMapping getMapping() {
return classMapping;
}

public class DocumentCollectionMapping extends AbstractClassMapping<Collection> {
private Collection mappedForm;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 {

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()
session.flush()
session.clear()
def service = session.datastore.getService(PersonAttributeDataService)

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)
}