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?
Many-to-many relationships are distinct from other relationship types because there is generally no reference to the parent entity in the child entity. Instead, create a third class to represent an associative entity (or cross-reference table) between the two entities.
Instead, create a third class to represent an associative entity (or cross-reference table) between the two entities. The cross-reference table must have columns for the primary key from each entity in the many-to-many relationship represented in the table.
A many-to-many relationship between two entities is a relationship where each instance of the parent entity corresponds to zero or more instances of the child entity, and vice-versa. In the music streaming app example, consider again the user-defined playlists.
Define one-to-one relationships A one-to-one relationship between two entities is a relationship where each instance of the parent entity corresponds to exactly one instance of the child entity, and vice-versa. For example, consider a music streaming app where the user has a library of songs that they own.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With