Realm ORM: how to deal with Maps?

后端 未结 2 1825
-上瘾入骨i
-上瘾入骨i 2021-01-02 04:14

I am creating an Android app and I need to persist a Map. I\'ve just started to use Realm ORM, as it supports one-to-one and one-to-many,

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 04:48

    Well, if you do have the luxury of reworking the persistence layer a bit, then the simplest solution is to not use a Map at all.

    A Map literally means that a particular String is associated with one object. You can do the same thing just by having that String be part of your RealmObject. Then you can query based on that.

    So any RealmResults` with a query for the string will contain one element, and that element will be the value of said map.

提交回复
热议问题