Let\'s say I want to do an INNER JOIN
between two entities Foo
and Bar
:
@Query(\"SELECT * FROM Foo INNER JOIN Bar ON F
Dao
@Query("SELECT * FROM Foo")
List findAllFooAndBar();
Class FooAndBar
public class FooAndBar {
@Embedded
Foo foo;
@Relation(parentColumn = "Foo.bar_id", entityColumn = "Bar.id")
List bar;
// If we are sure it returns only one entry
// Bar bar;
//Getter and setter...
}
This solution seems to work, but I'm not very proud of it. What do you think about it?
Edit: Another solution
Dao, I prefer to explicitly select but "*" will do the job :)
@Query("SELECT Foo.*, Bar.* FROM Foo INNER JOIN Bar ON Foo.bar = Bar.id")
List findAllFooAndBar();
Class FooAndBar
public class FooAndBar {
@Embedded
Foo foo;
@Embedded
Bar bar;
//Getter and setter...
}
edit: since Version 2.2.0-alpha01, room @Relation annotation can manage One-To-One relation