通过按日期排序来联接房间中的多个表

时间:2020-02-04 07:44:27

标签: android join android-room

我有以下3张桌子

Job 
id code jobStatus
1  ABC  Purchased
2  ABD  SELL
3  ABE  ACCEPTED
4  ABF  ACCEPTED
5  DCF  ACCEPTED


JobRaw  
id job_id createdOn key    value
1   3     6983456   status ASSIGNED
2   3     6986959   status ACCEPTED
3   4     6983460   status ASSIGNED
4   4     6986963   status ACCEPTED
5   5     6986961   status ACCEPTED


JobAddress
id job_id address
1  3      XYZ

我需要获得作业表,匹配的作业地址表中的所有详细信息,并且只有createdOn上的desc排序才能接受来自jobRaw的状态

@Transaction
@Query("SELECT * FROM job JOIN jobrawon job.id = jobraw.job_id WHERE code IN (:listOfCode) AND jobStatus = :status jobraw.`key` = status AND jobraw.value = :status ORDER BY jobraw.createdOn DESC")
List<JobAndJobAddress> getJobsByTourInternalJobCodeStatus_sortedOnAcceptedTime(long tourID, List<String> listOfInternalJobCodes, String status);

但是我收到了job_id 5的正确工作详细信息,但没有得到工作3和4的工作数据和工作地址。我想是因为3和4有多个记录。

这是我的嵌入式POJO类:

    public class JobAndJobAddress {
    @Embedded
    private Job job;

    @Relation(parentColumn = "id", entityColumn = "job_id")
    private List<JobAddress> jobAddress;

    @Relation(parentColumn = "id", entityColumn = "job_id", entity = JobRaw.class)
    private List<JobRaw> JobRaw;
   }

0 个答案:

没有答案