realm-swift: Realm.object returns NIL object when queried by primary key in Realm 10.0 beta2
!!! MANDATORY TO FILL OUT !!!
Goals
I have signed up with MongoDB Realm and installed the beta SDK. I have a Local Realm file that NEED not be synced with cloud. It is prepopulated with data and during app install - I move it to documents folder of the iOS (All this is existing code and works well when using the normal Realm SDK 4.4.x or 5.3.x).
After login to the Realm App - other than the Synced Realm, I also open this Non-Synced local realm using a different configuration. As the Grade class is NOT synced - I have NOT added the partition key or used _id as primary key.
class Grade: Object {
@objc dynamic var id=""
@objc dynamic var sno=0
@objc dynamic var name=""
@objc dynamic var version=0
@objc dynamic var timestamp = Date()
let linkedPrimarySkills = List<String>()
override static func primaryKey() -> String? {
return "id"
}
override static func indexedProperties() -> [String] {
return ["sno", "name"]
}
}
func sample() {
var config = Realm.Configuration(schemaVersion: 83)
guard let fileUrl = config.fileURL else {
throw AppError.invalidState("fileURL of realm config is nil")
}
config.fileURL = fileUrl.deletingLastPathComponent().appendingPathComponent("content.realm")
config.readOnly = false
let realm = try Realm(configuration: config)
let grades = realm.objects(Grade.self)
grades.forEach { (grade) in
print(grade) // prints all the objects as expected - I just added this to debug the issue to ensure objects exists
}
// note: I have opened the Realm file using Studio and data is present
guard let grade3 = realm.object(ofType: Grade.self, forPrimaryKey: "003") else {
print("G3 Not queryable by primary key") // prints this even that object is very much present
return // this is where it returns
}
print(grade3) // Never reaches here
}
I’m trying to query a object from Non-Synced Realm
Expected Results
Since the object is present - Non-Nil object should be returned
Actual Results
Even though the object is present - the realm.object function call returns NIL
I have tried using the realm.objects to dump all the objects in the specific collection - It lists down all the objects. But when using primary key - every object return nil.
It is NOT a read-only realm
Code Sample
Shared above
Version of Realm and Tooling
10.0.0-beta.2
Realm framework version: ?
Realm Object Server version: ? Using MongoRealm
Xcode version: ? 11.5
iOS/OSX version: ? 13.5
Dependency manager + version: ? CocoaPods
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (7 by maintainers)
Problem is fixed in 5.4.0. Thanks