ActiveAndroid custom primary key relationship error

591 views Asked by At

Please help me,

I need custom primary key name and relationship.

My Models:

@Table(name = "Items", id = "ItemId")
public class Item extends Model {

@Column(name = "Name")
public String name;

@Column(name = "Category")
public Category category;

public Item() {
    super();
}

public Item(String name, Category category) {
    super();
    this.name = name;
    this.category = category;
}

}
@Table(name = "Categories")
public class Category extends Model {

@Column(name = "Name")
public String name;

public List<Item> items() {
    return getMany(Item.class, "Category");
}

}

and my code:

List items = new Select().from(Item.class).execute();
Toast.makeText(this, items.get(0).name, Toast.LENGTH_LONG).show();

Result: Error: Invalid index 0, size is 0

I have modified primary key name on model and db from ItemId to Id:

@Table(name = "Items")

Result: OK

How do I fix this problem?

https://github.com/pardom/ActiveAndroid/issues/380

1

There are 1 answers

0
mg in dg On

I've find the problem

please edit Model.java in com.activeandroid Line 260

            if (entity == null) {
                TableInfo tableInfo = Cache.getTableInfo(entityType);
                entity = new Select().from(entityType)
                        .where(tableInfo.getIdName() + "=?", entityId).executeSingle();
            }