Permalink
Browse files

Merge branch '1.x'

  • Loading branch information...
2 parents 21b151a + ae3311d commit f12e58bc9f549398f295a8457f40c07236d288e5 @tomwidmer tomwidmer committed Mar 24, 2013
View
35 ...-gorm-mongo/src/test/groovy/org/grails/datastore/gorm/mongo/DBObjectConversionSpec.groovy
@@ -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)
View
6 ...mongo/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoEntityPersister.java
@@ -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;

0 comments on commit f12e58b

Please sign in to comment.