问题描述
虽然这个问题是关于ActiveAndroid,谁是熟悉的ORM也许可以回答这个问题。
Although this question is about ActiveAndroid, anyone who is familiar with ORMs could probably answer this question.
ActiveAndroid似乎并没有给你一个方法做很多一对多的关系,开箱即用。我发现,同时寻找解决的办法是这样的GitHub的问题:https://github.com/pardom/ActiveAndroid/issues/46
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");
}
这将导致像查询SELECT * FROM foo其中Foo.FooBar = FooBar.Id;
。这将返回最多一个富
行。我失去了一些东西?
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?
推荐答案
假设你要选择所有FOOS为一个特定的酒吧,你可以这样做:
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();
这篇关于主动Android的许多一对多的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!