Realm Android:将realmobject添加为数据模型类中的子数组

时间:2018-07-27 12:44:33

标签: android kotlin realm

我在kotlin android中有数据模型类,我想在应用程序在线时更新数据库,我的模型类如下所示

open class seller_dataRealmclass : RealmObject() {
    @PrimaryKey
    @SerializedName("id")
    @Expose
    var id: Int? = null
    @SerializedName("name")
    @Expose
    var name: String? = null
    @SerializedName("email")
    @Expose
    var email: String? = null
    @SerializedName("seller_type")
    @Expose
    var sellerType: Boolean? = false
    @SerializedName("location")
    @Expose
    var location: String? = null
    @SerializedName("depot_id")
    @Expose
    var depotId: Int? = null
    @SerializedName("sbl_no")
    @Expose
    var sblNo: String? = null
    @SerializedName("selling_frequency")
    @Expose
    var sellingFrequency: Boolean? = null
    @SerializedName("address")
    @Expose
    var address: String? = null
    @SerializedName("gstn")
    @Expose
    var gstn: String? = null
    @SerializedName("cr_no")
    @Expose
    var crNo: String? = null
    @SerializedName("aadhar_no")
    @Expose
    var aadharNo: String? = null
    @SerializedName("active")
    @Expose
    var active: Boolean? = null
    @SerializedName("deleted")
    @Expose
    var deleted: Boolean? = null
    @SerializedName("created")
    @Expose
    var created: String? = null
    @SerializedName("modified")
    @Expose
    var modified: String? = null
    @SerializedName("seller_accounts")
    @Expose
    var sellerAccounts: RealmList<SellerAccount>? = null
    @SerializedName("seller_mobiles")
    @Expose
    var sellerMobiles: RealmList<SellerMobile>? = null
}

在这个模型类中,我还有一个单独的真实对象,即SellerAccount和SellerMobile,我将其初始化为RealmList,因为来自服务器的数据将以JSON数组格式返回

当我尝试检索这样的数据

var seller_realm=mRealm?.createObjectFromJson(seller_dataRealmclass::class.java,seller_object.toString() )

大多数值都为空,并且卖方帐户SellerMobile未被保存,我尝试将其声明为数组,但是该领域不支持表内的数组格式

有什么主意吗?

0 个答案:

没有答案