ActiveAndroid自定义主键关系错误

时间:2015-06-18 08:04:33

标签: android activeandroid

请帮助我,

我需要自定义主键名称和关系。

我的模特:

@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");
}

}

和我的代码:

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

结果:错误:索引0无效,大小为0

我已修改模型上的主键名称,并将ItemId中的数据库修改为Id:

@Table(name = "Items")

结果:确定

如何解决此问题?

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

1 个答案:

答案 0 :(得分:0)

我发现了问题

请在com.activeandroid第260行编辑Model.java

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