I've tried to create simple many-to-many relationship using a auxiliary object, but it didn't work.
@Entity
public class Owner {
@Id long id;
@Relation(idProperty = "ownerId")
List<PetOwner> pets;
}
@Entity
public class Pet {
@Id long id;
@Relation(idProperty = "petId")
List<PetOwner> owners;
}
@Entity
public class PetOwner {
@Id long id;
long petId;
long ownerId;
@Relation Owner owner;
@Relation Pet pet;
}
When I compile my project. I get this code generated:
// THIS CODE IS GENERATED BY ObjectBox, DO NOT EDIT.
/**
* Cursor for DB entity "Owner".
*/
public final class OwnerCursor extends Cursor<Owner> {
private static Properties PROPERTIES = new Owner_();
// Property IDs get verified in Cursor base class
public OwnerCursor(Transaction tx, long cursor) {
super(tx, cursor, PROPERTIES);
}
@Temporary
public OwnerCursor() {
}
@Override
public final long getId(Owner entity) {
return entity.getId();
}
/**
* Puts an object into its box.
*
* @return The ID of the object within its box.
*/
@Override
public final long put(Owner entity) {
//**----->>>> MISSING RETURN STATEMENT**
}
// TODO @Override
protected final void attachEntity(Owner entity) {
// TODO super.attachEntity(entity);
entity.__boxStore = boxStoreForEntities;
}
// TODO do we need this? @Override
protected final boolean isEntityUpdateable() {
return true;
}
I've tried to do something simpler, but it's not supported yet, as said in the documentation:
Something like
@Entity
public class Pet {
@Id long id;
@Relation
List<Owner> owners;
}
@Entity
public class Owner {
@Id long id;
@Relation
List<Pet> pets;
}
would be much nicer, I think.
This will be supported very soon in upcoming 0.9.8 (if plans do not change).
Side note: I would have expected a pet to have a single owner. This is fully supported right now.
Nice!
But the missing return statement I mentioned, wasn't something supposed to be there right now, or did I try to do something not supported yet?
PS: But that's why sometimes people go to court to decide who gets to keep the dog, cat, whatever, after a divorce. :c Anyway, I was just testing.
The put() method of Owner was just empty?
Yup
On Mon, Jan 30, 2017, 08:55 greenrobot notifications@github.com wrote:
The put() method of Owner was just empty?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/greenrobot/ObjectBox/issues/22#issuecomment-276044934,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACEqNXd9bCXi2uadOoomS-R06R2fbFzLks5rXc_MgaJpZM4Lw_yW
.
@greenrobot How are M:N relations currently supported amoungst 1 single class?
My use case is @Entity class Person with typically 2 parents and 1..* children, all class Person objects.
Does this require an @Entity class ParentChildRelation with long parentId and long childId to make this work?
FYI: We are currently working on this. First step will be standalone to-many relations. In the future we will expand this with backlinks (which will enable M:N; until then you could workaround with two to-many relations).
One-way to-many relations were introduced in ObjectBox 0.9.14. Backlinks to those will come at a later release (rather soon-ish).
Do you have any milestone to add Backlinks for many-to-many relationships?
@jpmcosta We need to prioritize feature requests. Would you be available for a quick chat? Please send us a line using contact at objectbox dot IO. Thank you!
@greenrobot Any update on this ? by when it will be released
Tracking support for to-many relations with backlink in #407.
This ticket is assigned a milestone for the release of one-way to-many. As that already happened, closing. -ut
Most helpful comment
Do you have any milestone to add Backlinks for many-to-many relationships?