DATAMONGO-1988 - Polishing.
Match exactly for either top-level properties of leaf-properties instead of accepting the property/field name suffix. Original pull request: #565.
This commit is contained in:
@@ -833,7 +833,7 @@ public class QueryMapper {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#isIdKey()
|
||||
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#isIdField()
|
||||
*/
|
||||
@Override
|
||||
public boolean isIdField() {
|
||||
@@ -842,7 +842,9 @@ public class QueryMapper {
|
||||
: entity.getIdProperty();
|
||||
|
||||
if (idProperty != null) {
|
||||
return name.endsWith(idProperty.getName()) || name.endsWith(idProperty.getFieldName());
|
||||
|
||||
return name.equals(idProperty.getName()) || name.equals(idProperty.getFieldName())
|
||||
|| name.endsWith("." + idProperty.getName()) || name.endsWith("." + idProperty.getFieldName());
|
||||
}
|
||||
|
||||
return DEFAULT_ID_NAMES.contains(name);
|
||||
|
||||
@@ -783,6 +783,16 @@ public class QueryMapperUnitTests {
|
||||
assertThat(document.get("sample._id"), instanceOf(ObjectId.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1988
|
||||
public void matchesExactFieldNameToIdProperty() {
|
||||
|
||||
Query query = query(where("sample.iid").is(new ObjectId().toHexString()));
|
||||
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
|
||||
context.getPersistentEntity(ClassWithEmbedded.class));
|
||||
|
||||
assertThat(document.get("sample.iid"), instanceOf(String.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1988
|
||||
public void leavesNonObjectIdStringIdRepresentationUntouchedWhenReferencingIdProperty() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user