【发布时间】:2020-06-20 08:24:37
【问题描述】:
我想使用 @Relation 从一对一的关系中获取数据,但需要为孩子提供条件
@Entity
public class User {
@PrimaryKey public long userId;
public String name;
public int age;
}
@Entity
public class Library {
@PrimaryKey public long libraryId;
public long userOwnerId;
public String code;
}
public class UserAndLibrary {
@Embedded public User user;
@Relation(
parentColumn = "userId",
entityColumn = "userOwnerId"
)
public Library library;
}
@Transaction
@Query("SELECT * FROM User") // I want to get where library.code = "123"
public UserAndLibrary getUsersAndLibraries();
我想要的数据是来自用户的所有数据,其中 library.code = "123" 我知道我可以使用@Embedded,但我的数据使用许多相同的名称,我不想使用前缀。所以我想知道如何使用@Relation 来做到这一点
谢谢
【问题讨论】:
标签: android android-room