-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relation list order #1144
Comments
There are proposed changes and a request for input in #243 (comment) We welcome any feedback or other suggestions. |
You can add a list of long-IDs to the Event-entity and persist those with a converter:
The converter is responsible for converting the List-type to something you can persist in ObjectBox. For ease of use, I post some kotlin-code here of how I use it with Gson for such a case, since I already have Gson in my project, but maybe just for this, you should simply convert the list to a string of comma-separated values and vice versa:
And last but not least, you can then set a comparator on the ToMany-field to tell it to sort its content according to the order of the teamsOrder-list (again kotlin-code, but you may get the idea):
See https://objectbox.io/docfiles/java/current/io/objectbox/relation/ToMany.html#setComparator(java.util.Comparator) for details |
I have a problem that is pretty much similar to #243.
But I can add some details to it.
Let's say I have a class called Event that defines an event and the attendees (teams).
There is an overall list of all teams and each team can be in multiple events.
That is where the challenge comes in.
I need to be able to manually 'sort'/rearrange the teams in each event. The order matters.
I am struggling to store the 'sortorder' anywhere. I can not add it to the team class since the identical team can be in several events and with that will have a unique position in each event. That would leave the event class as the logical place.
But I am not seeing a good way to do that either.
Does ObjectBox support a solution for that? Basically maintaining the sortorder of the ToMany in ANY way?
The text was updated successfully, but these errors were encountered: