问题
Although this question is about ActiveAndroid, anyone who is familiar with ORMs could probably answer this question.
ActiveAndroid doesn't seem to give you a way to do many-to-many relationships out of the box. What I found while searching for a solution was this GitHub issue: https://github.com/pardom/ActiveAndroid/issues/46
I understand that it's explicitly creating the relationship table, but I don't understand how the following part is supposed to do anything useful:
public List<Foo> foos() {
return getMany(Foo.class, "FooBar");
}
public List<Bar> bars() {
return getMany(Bar.class, "FooBar");
}
This would result in a query like SELECT * FROM Foo where Foo.FooBar = FooBar.Id;
. This would return at most one Foo
row. Am I missing something?
Don't you need a query involving a join?
回答1:
Let's say you want to select all Foos for one specific Bar, you would do this:
List<Foo> foos = ((Foo) new Select().from(FooBar.class)
.where("Foo = ?", this.getId())
.executeSingle()).foos();
来源:https://stackoverflow.com/questions/17645900/active-android-many-to-many-relationship