-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add findOrCreate helper methods #6168
Conversation
} | ||
|
||
// Find existing permission object or create new one | ||
Permission permission = permissions.where().equalTo("role.name", roleName).findFirst(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if there are already multiple permission with the provided role?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it is a List sync will remove duplicates. Ideally, this should have been a Set, but we are still lacking Core/Sync support for it.
// Find existing role or create new one | ||
Role role = realm.where(Role.class).equalTo("name", roleName).findFirst(); | ||
if (role == null) { | ||
role = realm.createObject(Role.class, roleName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user still needs to find the role in order to add members to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but you can do that through the permission object returned using findOrCreate("new-role").getRole().addMember("foo")
This mirrors API methods found in the Swift and Objective-C API's.
In their case it exists on the
RealmList<Permission>
object, butThat is an extension method on the
RealmList<Permission>
only, which is impossible to achieve in Java unless we subclassRealmList
. This is achievable and we need to do it to support the ACL property better anyway, but....It is also much harder to do and is one extra level of indirection on
RealmPermissions
andClassPermissions
so having it directly on those classes will be nicer anyway.