Home » Android » Combining 2 RealmList object in realm android

Combining 2 RealmList object in realm android

Posted by: admin November 1, 2017 Leave a comment

Questions:

How to use realm relationships using 2 RealmList, here the example.

Class Menu

    public class Menu extends RealmObject {
    @SerializedName("name")
    private String name;

    @SerializedName("module")
    private String module;

    @SerializedName("controller")
    private String controller;

    @SerializedName("parent_module")
    private String parentModule;

    @SerializedName("status")
    private Boolean status;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getController() {
        return controller;
    }

    public void setController(String controller) {
        this.controller = controller;
    }

    public String getParentModule() {
        return parentModule;
    }

    public void setParentModule(String parentModule) {
        this.parentModule = parentModule;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }
}

Class Privilege

  public class Privilege extends RealmObject {

    private String module;

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

}

and i’m using this method to save them.

@Override
public void saveMenuPrivilege(RealmList<Menu> menu, RealmList<Privilege> privileges) {

}

now what makes me confuse is, there is a condition where if the module in class Menu has the same module in class Privilege, then set the active field for that module in class Menu to be “true”. How to do that? or i’m doing it wrong using the code above?

Thanks in advance

Answers:

All ready have the answer, just testing all by myself. 😀