Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '1.x'

  • Loading branch information...
commit f12e58bc9f549398f295a8457f40c07236d288e5 2 parents 21b151a + ae3311d
Tom Widmer tomwidmer authored
35 grails-datastore-gorm-mongo/src/test/groovy/org/grails/datastore/gorm/mongo/DBObjectConversionSpec.groovy
View
@@ -78,6 +78,41 @@ class DBObjectConversionSpec extends GormDatastoreSpec {
Boat.count() == 1
}
+ void "Test that an entity can be round-tripped to dbo and back"() {
+ given:"A domain model with embedded associations that have non-embedded associations"
+ createCrew()
+
+ when:"The model is converted to a dbo and back"
+ Boat boat = Boat.findAll().get(0).dbo as Boat
+
+ then:"The copy matches the original"
+ boat != null
+ boat.name == "The Float"
+ boat.captain != null
+ boat.captain.name == 'Bob'
+ boat.crew.size() == 2
+ boat.crew[0].name == 'Fred'
+ boat.crew[0].captain != null
+ boat.crew[0].captain.name == 'Bob'
+ boat.captain.shipmates.size() == 1
+
+ when:"The association is updated"
+ boat.crew.pop()
+ boat.save(flush: true)
+ boat = boat.dbo as Boat
+
+ then:"The model is correct"
+ boat != null
+ boat.name == "The Float"
+ boat.captain != null
+ boat.captain.name == 'Bob'
+ boat.crew.size() == 1
+ boat.crew[0].name == 'Fred'
+ boat.crew[0].captain != null
+ boat.crew[0].captain.name == 'Bob'
+ boat.captain.shipmates.size() == 1
+ }
+
private createCrew() {
final captain = new Captain(name: "Bob").save()
final firstMate = new Sailor(name: "Jim", captain: captain)
6 grails-datastore-mongo/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoEntityPersister.java
View
@@ -135,7 +135,7 @@ protected void setEmbeddedCollection(final DBObject nativeEntry, final String ke
return;
}
- nativeEntry.put(key, embeddedEntries.toArray());
+ nativeEntry.put(key, embeddedEntries);
}
/**
@@ -198,8 +198,8 @@ protected void loadEmbeddedCollection(EmbeddedCollection embeddedCollection,
instances = new HashSet<Object>();
}
- if (embeddedInstances instanceof BasicDBList) {
- BasicDBList list = (BasicDBList)embeddedInstances;
+ if (embeddedInstances instanceof List) {
+ List list = (List)embeddedInstances;
for (Object dbo : list) {
if (dbo instanceof BasicDBObject) {
BasicDBObject nativeEntry = (BasicDBObject)dbo;
Please sign in to comment.
Something went wrong with that request. Please try again.