Uploaded image for project: 'Realm Java SDK'
  1. Realm Java SDK
  2. RJAVA-303

Document what overriding field names mean

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      <!---

      Questions: If you have questions about how to use Realm, ask on
      StackOverflow.
      We monitor the realm tag.

      Feature Request: Just fill in the first two sections below.

      Bugs: To help you as fast as possible with an issue please describe your issue
      and the steps you have taken to reproduce it in as many details as possible.

      -->

      Goal

      Filter table by field names specified with RealmField.

      Expected Results

      No crashes.

      Actual Results

      App crashes:

      Caused by: java.lang.IllegalArgumentException: Invalid query: field '_id' not found in class 'cards'.
         at io.realm.internal.fields.CachedFieldDescriptor.compileFieldDescription(CachedFieldDescriptor.java:80)
         at io.realm.internal.fields.FieldDescriptor.compileIfNecessary(FieldDescriptor.java:292)
         at io.realm.internal.fields.FieldDescriptor.getColumnIndices(FieldDescriptor.java:185)
         at io.realm.RealmQuery.equalToWithoutThreadValidation(RealmQuery.java:309)
         at io.realm.RealmQuery.in(RealmQuery.java:551)
         at io.realm.RealmQuery.in(RealmQuery.java:531)
         ...
      

      Steps & Code to Reproduce

      1. Create a class with a custom table name and a custom field name.
      2. Try to query for items using field name passed to RealmField.

      Code Sample

      Constants replaced with values.

      @RealmClass(name = "cards")
      public class CardModel implements RealmModel {
      
          @PrimaryKey
          @Required
          @RealmField(name = "_id")
          private String mKey;
      
          // getters and setters
      }
      
      ...
      
      try (final Realm realm = mRealmProvider.get()) {
      	final RealmResults<CardModel> all1 = realm.where(CardModel.class)
      			.in("mKey", map(keys)) // will NOT crash here
      			.findAll();
      	final RealmResults<CardModel> all2 = realm.where(CardModel.class)
      			.in("_id", map(keys)) // will crash here
      			.findAll();
      }
      

      Version of Realm and tooling

      Realm version(s): 5.0.0

      Realm sync feature enabled: no

      Android Studio version: 3.0.1

      Which Android version and device: API 24, Emulator

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: