Active Android many-to-many relationship

…衆ロ難τιáo~ 提交于 2019-12-06 22:41:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!