Hello. Can someone reproduce the Schema for my RealmObject? The schema that was produced when Developer Mode was ON didn’t got my field “meniu”. Also, what is the best way to have an array of RealmObjects as a field of one RealmObject?
class Restaurant : RealmObject {
@PrimaryKey
var _id: String = ""
var userID: String = ""
var name: String = ""
var adresa: String? = null
var telefon: Long? = null
var meniu: List<Product> = emptyList()
}
Sorry, so have you resolved the issue? It sounds like your SDK model thought the meniu field was a list of links but the json schema in the UI only thought it was a list of strings. One part of it is that your previous schema for Product was incorrect but I get the sense you know that since you fixed it
class Product : EmbeddedRealmObject {
var name: String = ""
var category: String = ""
var description: String? = ""
var price: Float = 0F
var imagine: String? = null
}
class Restaurant : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId.create()
var userID: String = ""
var name: String = ""
var adresa: String? = null
var telefon: Long? = null
var meniu: RealmList<Product> = realmListOf()
}
The Restaurant schema is good but I dont understand why the Product Schema was not produced. Also, Product collection was not created, probably because is embedded and is created inside Meniu field. I am right? Also, the data modeling is done how is supposed to be?
When you have developer mode ON, you can create all your schemas from your client side. I infer you are creating Android App, so you can create schema within the app itself, and when you run the app, the schema will be populated on the cloud.
All the fields may or may not show on the cloud if the data is not yet added for them. The schema of embedded classes will appear as and when you add data to those fields on the device.
If your data is not showing, either the schema needs to change or the way you are adding data. Could you share the cloud realm app id?
Hey, if you look at your schema you will see that the schema for product is embedded within the schema for restaurant. In MongoDB / Realm there are two ways to model your data:
Relationships: the two schema represent different collections. The primary keys (string in your case) are used to denote the relationship between the schemas for the field you define.
Embedded: one schema “owns” the other and they both map to the same collection. Embedding documents is a powerful paradigm in MongoDB.