How to add conditions to the relation?
For example, we have object Pet
@Entity
public class Pet {
@ PrimaryKey
int id;
int userId;
String name;
String type;
// other fields
}
and object User
public class User {
int id;
// other fields
}
For getting user with pets we make object
public class UserAllPets {
@Embedded
public User user;
@Relation(parentColumn = "id", entityColumn = "userId", entity = Pet.class)
public List<PetNameAndId> pets;
}
How is possible to get user with pets by type? Only dogs or only cats
Here is dao class:
@Dao
public abstract class UserDao {
@Query("SELECT * FROM `users`")
public abstract UserAllPets getUserWithPets();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…