From 56448d8e091c3301b070c532b34298d7df08ec77 Mon Sep 17 00:00:00 2001 From: Ciaran O'Reilly Date: Tue, 12 Jun 2018 15:11:34 +0200 Subject: [PATCH] Fix bug that wouldn't allow selecting specific columns of a table --- .../java/com/orm/inflater/field/EntityFieldInflater.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/orm/inflater/field/EntityFieldInflater.java b/library/src/main/java/com/orm/inflater/field/EntityFieldInflater.java index 9eda8f8e..d95cfa24 100644 --- a/library/src/main/java/com/orm/inflater/field/EntityFieldInflater.java +++ b/library/src/main/java/com/orm/inflater/field/EntityFieldInflater.java @@ -20,7 +20,11 @@ public EntityFieldInflater(Field field, Cursor cursor, Object object, Class f @Override public void inflate() { try { - long id = cursor.getLong(cursor.getColumnIndex(NamingHelper.toColumnName(field))); + int columnIndex = cursor.getColumnIndex(NamingHelper.toColumnName(field)); + if (columnIndex < 0) { + return; + } + long id = cursor.getLong(columnIndex); field.set(object, (id > 0) ? SugarRecord.findById(fieldType, id) : null); } catch (IllegalAccessException e) { Log.e(LOG_TAG, String.format("Error while inflating entity field %s", field), e);