Reputation: 711
I started using realm. it seemed to work fine, but I have some questions. When I use realm for simple object with primitive fields, everything is ok. But I'm facing issues using it for complex objects.
For example I have a class Passenger
. It has several fields
Segment segment;
Documents documents;
....
Each field also has sub objects. Segment class
Flight flight;
Arrival arrival;
int pnrRequest;
So as I understand I will have several tables and I need one-to-many relations to connect this tables. What i want is to store passenger list inside database.
The problem is that I already have this classes as a model, but they dont extend RealmObject. I don't want to have duplicate classes one for model and one for database. Is there a way to avoid duplication of files and conversion from one model to another?
Upvotes: 1
Views: 1568
Reputation: 5371
According to documentation it's posible:
An alternative to extending the RealmObject base class is implementing the RealmModel interface and adding the @RealmClass annotation.
Upvotes: 1
Reputation: 20126
Realm requires that all models that should be persisted must extend RealmObject
or implement the interface RealmModel
(see https://realm.io/docs/java/latest/#realmmodel-interface). If neither of these approaches work for you, you will need to duplicate the class and have conversion methods between them.
Upvotes: 1