I'm getting started with realm and trying to figure out the best way to write my model layer, so after overthinking about it I decide to ask here to get some opinions. Here we go:
I'm writing a realm version of these tables:
Account
id - String (PK)
Name - String
Type - Int
Checking Account
id - String (FK PK)
In this case a Checking Account is an Account, but realm still not support inheritance (I think using Account as a superclass would be the better way to figure these tables out in the model layer)
This is what I actually did with realm:
Account class:
import Foundation
import RealmSwift
class Account: Object {
dynamic var id = NSUUID().UUIDString
dynamic var name = ""
dynamic var type = 3
override static func primaryKey() -> String {
return "id"
}
}
Checking Account class:
import Foundation
import RealmSwift
class CheckingAccount: Object {
dynamic lazy var id: String = {
return self.account.id
}()
dynamic var account = Account()
convenience init(name: String, type: AccountType) {
self.init()
self.account.name = name
self.account.type = type.rawValue
}
override static func primaryKey() -> String? {
return "id"
}
}
What about it? It's a "Don't do" way to figure out my SQL tables with realm?
Thank you!