活跃的Android多对多关系

Bar*_*Rho 8 sql android activeandroid

虽然这个问题与ActiveAndroid有关,但任何熟悉ORM的人都可以回答这个问题.

ActiveAndroid似乎没有为您提供开箱即用的多对多关系的方法.我在寻找解决方案时发现的是这个GitHub问题:https://github.com/pardom/ActiveAndroid/issues/46

我知道它是显式创建关系表,但我不明白以下部分应该如何做有用的事情:

public List<Foo> foos() {
    return getMany(Foo.class, "FooBar");
}
public List<Bar> bars() {
    return getMany(Bar.class, "FooBar");
}
Run Code Online (Sandbox Code Playgroud)

这将导致类似的查询SELECT * FROM Foo where Foo.FooBar = FooBar.Id;.这最多只返回Foo一行.我错过了什么吗?

你不需要涉及连接的查询吗?

小智 4

假设您想为一个特定的 Bar 选择所有 Foos,您可以这样做:

List<Foo> foos = ((Foo) new Select().from(FooBar.class)
                .where("Foo = ?", this.getId())
                .executeSingle()).foos();
Run Code Online (Sandbox Code Playgroud)