Repository navigation
Add findOrCreate helper methods - #6168
Merged
Merged
Conversation
nhachicha
reviewed
Sep 19, 2018
| } | ||
|
|
||
| // Find existing permission object or create new one | ||
| Permission permission = permissions.where().equalTo("role.name", roleName).findFirst(); |
Collaborator
There was a problem hiding this comment.
what if there are already multiple permission with the provided role?
Contributor
Author
There was a problem hiding this comment.
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); |
Collaborator
There was a problem hiding this comment.
The user still needs to find the role in order to add members to it
Contributor
Author
There was a problem hiding this comment.
Yes, but you can do that through the permission object returned using findOrCreate("new-role").getRole().addMember("foo")
nhachicha
approved these changes
Sep 24, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
RealmPermissionsandClassPermissionsso having it directly on those classes will be nicer anyway.