-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Many to many relationship #46
Comments
I'm also wondering how to do this. |
Did you try: public class Foo extends Model {
[…]
}
public class Bar extends Model {
[…]
}
public class FooBar extends Model {
@Column(name = "foo", onDelete=ForeignKeyAction.CASCADE)
public Foo foo;
@Column(name = "bar" onDelete=ForeignKeyAction.CASCADE)
public Bar bar;
public List<Foo> foos() {
return getMany(Foo.class, "FooBar");
}
public List<Bar> bars() {
return getMany(Bar.class, "FooBar");
}
} This will need my branch: https://github.com/vonloxley/ActiveAndroid, because of #32 and is completely untested. You need to define a unique index on FooBar(foo, bar) as well, which isn’t possible with AA right now. HTH |
Thanks, finally I did it that way. |
@vonloxley has it right. This is common db architecture for many-to-many relationships. Rails ActiveRecord handles it a bit differently, whereas this is a bit more transparent. |
So this is the way to do many-to-many with ActiveAndroid, through a join Model/Table? |
would be nice if there was some analogue to has_and_belongs_to_many |
How does one define a "unique index on FooBar" as mentioned above? |
Could you give us a more detailed example? I still can't manage to get a many-to-many relationship working. Do I have to explicitly create the "FooBars" when creating a Foo/Bar ? |
Here is my answer on another place: http://stackoverflow.com/questions/26207948/activeandroid-many-to-many-relationship/39203783#39203783 |
Hi,
How could I create a many to many relationship?
The text was updated successfully, but these errors were encountered: