roscopeco/ormdroid

One to Many Relation

Closed this issue · 4 comments

I thought ORMDroid can handle one to many relations as :

public class MyObjet extends Entity
{
    // ...
    private ArrayList<MyOtherObject> otherObjects;
}

public class MyOtherObject extends Entity
{
    // ...
}

but not :

com.roscopeco.ormdroid.TypeMappingException: Model MyObjet has unmappable field: public java.util.ArrayList otherObjects

This is how I solved it:

public class ManyEntity extends Entity {
public int id;
public String child_name;
public ParentEntity parent;

public ManyEntity() {
    this(null,null);
}

public ManyEntity(String child_name, ParentEntity parent) {
    // TODO Auto-generated constructor stub
    this.child_name = child_name;
    this.parent = parent;
}

}

This is currently being worked on, with a new type mapping (for java.util.List) and some other code changes that will support this behaviour. In the meantime, it can be emulated with methods and non-persistent fields.

+1 Just needed this.

@roscopeco Can we actually close this ?