Document what overriding field names mean
See original GitHub issueGoal
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
- Create a class with a custom table name and a custom field name.
- 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
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Overriding field names for Description, Value and Flag fields
Overriding names are displayed instead of the default name in table columns, labels, and in the Formula Builder. The overriding names for ...
Read more >Document Customization - Overrides Tab Page - Xytech Systems
This tab page allows you to define a variety of overriding custom properties for standard fields in the table selected on the DOCUMENT...
Read more >Overriding Salesforce Field Metadata - Salesforce Help
You can override the field metadata that the sfdcDigest transformation extracts from a Salesforce object to make the data appear differently in a...
Read more >Configure field overrides | Grafana documentation
Overrides allow you to customize visualization settings for specific fields or series. This is accomplished by adding an override rule that targets a...
Read more >Understand Field Type Detection and Naming Improvements
Field name clean-up ... Field names that contain specific characters or capitalized in a certain way are renamed. Field values that include square...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is exactly the reason why it should be used in typed queries as well, because when you (accidentally) rename the java field
name
to e.g.firstName
, you’ll still have the properFIELD_NAME
for realm queries.If you have it this way, then there’s no IDE help and you may easily end up having
FIELD_NAME
different than javaname
.Also another use case for using it in queries is, that then you can have (in kotlin) something like this:
And you can still use:
Which then provides more type-safety, because from code you may access whatever name you added, but in queries you use fields you defined in annotation.
Yes, I can see the problem. Honestly, I think a better solution to your problem would be if we started allowing non-polymorphic inheritance, which would allow for a base class with shared fields. So far we have not done that because we feared that not having polymorphism would really trip people up but both our Cocoa binding and ObjectBox do this, so we should probably revisit that decision.
The reason I’m hesitant about “just” allowing queries on both internal and Java names is that it muddles the layers between Java defined names and internal names and we need to enforce that you cannot use an internal name that is already being used in the Java model class.
I’ll need to think a little about this.