Permalink
Browse files

fix for GPMONGODB-191 "Dynamic property Criteria not working"

  • Loading branch information...
1 parent d2bf312 commit 547b54a3e63b23be28360b4f7adf05dd0d47caae @graemerocher graemerocher committed Apr 10, 2012
View
4 ...s-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractDatastore.java
@@ -192,4 +192,8 @@ protected boolean isIndexed(PersistentProperty property) {
final Property keyValue = pm.getMappedForm();
return keyValue != null && keyValue.isIndex();
}
+
+ public boolean isSchemaless() {
+ return false;
+ }
}
View
7 grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Datastore.java
@@ -99,4 +99,11 @@
* @param skip whether to skip or not
*/
void setSkipValidation(Object o, boolean skip);
+
+ /**
+ * Whether the datastore is schema-less. That is it allows changes to the schema runtime, dynamic attributes etc.
+ *
+ * @return True if it does
+ */
+ boolean isSchemaless();
}
View
17 ...atastore-gorm-mongo/src/test/groovy/org/grails/datastore/gorm/mongo/SchemalessSpec.groovy
@@ -48,6 +48,23 @@ class SchemalessSpec extends GormDatastoreSpec{
newResults.size() == 1
newResults[0].name == 'Pineapple'
newResults[0]['color'] == 'Yellow'
+
+ when:"A dynamic finder is used on a schemaless property"
+ session.clear()
+ def plant = Plant.findByColor("Yellow")
+
+ then:"The dynamic finder works"
+ plant.name == "Pineapple"
+
+ when:"A criteria query is used on a schemaless property"
+ session.clear()
+ plant = Plant.createCriteria().get {
+ eq 'color', 'Yellow'
+ }
+
+ then:"The dynamic finder works"
+ plant.name == "Pineapple"
+
}
}
View
2 grails-datastore-gorm/src/main/groovy/grails/gorm/CriteriaBuilder.java
@@ -964,7 +964,7 @@ protected void validatePropertyName(String propertyName, String methodName) {
if (property == null && persistentEntity.getIdentity().getName().equals(propertyName)) {
property = persistentEntity.getIdentity();
}
- if (property == null) {
+ if (property == null && !session.getDatastore().isSchemaless()) {
throw new IllegalArgumentException("Property [" + propertyName +
"] is not a valid property of class [" + persistentEntity + "]");
}
View
5 ...ls-datastore-mongo/src/main/groovy/org/grails/datastore/mapping/mongo/MongoDatastore.java
@@ -333,4 +333,9 @@ public void destroy() throws Exception {
if(mongo != null)
mongo.close();
}
+
+ @Override
+ public boolean isSchemaless() {
+ return true;
+ }
}

0 comments on commit 547b54a

Please sign in to comment.