Permalink
Browse files

Fix for GPMONGODB-285: Mongo deletes do not cascade in a hasMany/belo…

…ngs to relationship
  • Loading branch information...
cholick committed Mar 16, 2013
1 parent 3acb01a commit d405fbb446a5e25fdcf9839f6623518eff42d483
@@ -33,6 +33,7 @@
import org.grails.datastore.mapping.engine.AssociationIndexer;
import org.grails.datastore.mapping.engine.EntityAccess;
import org.grails.datastore.mapping.engine.NativeEntryEntityPersister;
+import org.grails.datastore.mapping.engine.Persister;
import org.grails.datastore.mapping.engine.PropertyValueIndexer;
import org.grails.datastore.mapping.model.EmbeddedPersistentEntity;
import org.grails.datastore.mapping.model.MappingContext;
@@ -720,6 +721,19 @@ public Object doInDB(DB con) throws MongoException, DataAccessException {
});
}
+ @Override
+ protected void cascadeDeleteCollection(Collection collection) {
+ Persister persister = null;
+ for (Iterator iter = collection.iterator(); iter.hasNext(); ) {
+ Object child = iter.next();
+ if(persister == null) {
+ persister = session.getPersister(child);
+ }
+ persister.delete(child);
+ iter.remove();
+ }
+ }
+
protected DBObject createDBObjectWithKey(Object key) {
DBObject dbo = new BasicDBObject();
if (hasNumericalIdentifier || hasStringIdentifier) {

0 comments on commit d405fbb

Please sign in to comment.