ActiveAndroid
ActiveAndroid copied to clipboard
custom primary key relationship error
Hi 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<Item> 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?
I found 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();
}