Context :
- Some content are protected by groups. (Content class has 2 RealmLists of groups, the first "groupsOneOf" an the second "groupsAllOf")
- Users can be in groups (User has one RealmList "groups")
- Some content is available only for user which is at least in one of the content's group.
- Some content is available only for user which is in all of content's group.
For "at least in one of the content's group", I found 'in' operator in documentation :
This allows you to test if objects match any value in an array of values.
But for the second, no way to perform this kind of query. I searched solution in other posts but some people seems to say that's not supported right now. In iOS, it seems to be available with NSPredicate but not in java.
Here is my code :
fun <E> RealmQuery<E>.groupsAllowed(): RealmQuery<E>{
val groups = arrayListOf<String>()
realm.queryUserConnected()?.findFirst()?.groups?.forEach { groups.add(it.id) }
if(groups.isEmpty()){
isEmpty("groupsAllOf")
isEmpty("groupsOneOf")
}else{
beginGroup()
beginGroup()
isEmpty("groupsOneOf")
or()
`in`("groupsOneOf.id", groups.toTypedArray())
endGroup()
beginGroup()
isEmpty("groupsAllOf")
or()
//TODO
endGroup()
endGroup()
}
return this
}
Some help would be greatly appreciated.
from Realm (Android/Kotlin) - How to perform a query which allows you to test if all objects match as a part of values in an array of values
No comments:
Post a Comment