我在Contract,Farmer和Crop
之间有以下关系作物:
public class Contract extends RealmObject {
@PrimaryKey
public String internalId;
public Crop crop;
public Farmer farmer;
}
合同:
Stream
我想从属于农民的所有合同中选择不同的作物。我该如何存档?
答案 0 :(得分:0)
Realm 3.5.0 +:
public class Crop extends RealmObject {
@PrimaryKey
public String publicId;
public String cropName;
@LinkingObjects("contract")
public final RealmResults<Contract> cropOf = null;
}
然后
realm.where(Crop.class)
.equalTo("cropOf.farmer.farmerId", farmerId)
.distinct("cropName");