8

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?

Barum Rho
  • 2,743
  • 1
  • 20
  • 21
  • Here is my answer on another place: [Activeandroid Many-to-many](http://stackoverflow.com/questions/26207948/activeandroid-many-to-many-relationship/39203783#39203783) – Prilaga Aug 29 '16 at 10:23

1 Answers1

4

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();