简体   繁体   English

在roomdb android 中面临@Relation 的问题

[英]facing issue with @Relation in roomdb android

 public class StockRelation extends Item {
        @Relation(parentColumn = "mpc", entityColumn = "itempc", entity = Location.class)
        public List<Location> locationList;
    }

    public class RStockRelation extends StockRelation{
       @Relation(parentColumn = "mpc", entityColumn = "location_itemid", entity = Location.class)
       public List<Location> locationList;
    }

here only the @Relation is getting change whereas the other things are the same.这里只有@Relation 发生变化,而其他事情是一样的。 and I want to do a sort order for locationlist based on a column in the Location table in the query itself.我想根据查询本身的 Location 表中的列对 locationlist 进行排序。 So how to have final data in one object instead of two different StockRelation and RStockRelation.那么如何在一个 object 而不是两个不同的 StockRelation 和 RStockRelation 中拥有最终数据。 Is there any other way I can fix this有没有其他方法可以解决这个问题

As I understood you have two tables (entities) and in general you want apply two left joins from first table to the second one on different fields - to get in result your first object with connected two different location lists (but use Room-Relation annotation instead of left joins).据我了解,您有两个表(实体),通常您希望在不同字段上应用从第一个表到第二个表的两个左连接 - 以获得连接两个不同位置列表的第一个 object(但使用 Room-Relation 注释而不是左连接)。

If it's what you want, try this:如果这是你想要的,试试这个:

public class StockRelation extends Item {
@Relation(parentColumn = "mpc", entityColumn = "itempc", entity = Location.class)
public List<Location> locationList1;
@Relation(parentColumn = "mpc", entityColumn = "location_itemid", entity = Location.class)
public List<Location> locationList2;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM