Skip to content Skip to sidebar Skip to footer

How To Get Data From @relation Where Child Condition

I want to get data from One to One Relationship using @Relation but with condition for the child @Entity public class User { @PrimaryKey public long userId; public String n

Solution 1:

With @Relation you cannot set "child" condition. So your choice if you don't want to deal with tables' joins - is to replace your parent/child classes in UserAndLibrary:

publicclassUserAndLibrary{
    @Embeddedpublic Library library;
    @Relation(
         parentColumn = "userOwnerId",
         entityColumn = "userId"
    )public User user;
}

and dao:

@Transaction@Query("SELECT * FROM library Where code = :code") // now you can set condition
public UserAndLibrary getUsersAndLibraries(String code);

Post a Comment for "How To Get Data From @relation Where Child Condition"