greenlaw110/play-morphia — Issue #44: When model contains blob field, subsequent saves results in multiple GridFS records with duplicate names
Author: bbigard
Created: 2011-11-10 15:39:12+00:00
State: open

I could be using the library incorrectly, but when updating a model with a blob field, additional records are created in the GridFs table with the same name. Seems like deleteBlobs with some logic around it should be called prior to saveBlobs in the Model save2 method.

@Test
public void subsequentSaveResultsInMultipleRecordsWithDuplicateNames() {
File originalImageFile = VirtualFile.fromRelativePath("/public/images/_avatar/default.png").getRealFile();
File newImageFile = VirtualFile.fromRelativePath("/public/images/_avatar/default-24x24.png").getRealFile();

Racer r = new Racer();
r.fullName = "Test User";
r.image = new Blob(originalImageFile, "image/png");
r.save();

r = Racer.find("fullName", "Test User").first();

assertNotNull(r);

r.image = new Blob(newImageFile, "image/png");
r.save();

String name = r.getBlobFileName("image");

DBObject queryObj = new BasicDBObject("name", name);
List list = MorphiaPlugin.gridFs().find(queryObj);

assertEquals(1,list.size());
}