Search code examples
javaandroiddbflow

DBFlow issue regarding oneToMany and ForeignKey


I want to use the OneToMany relation in DBFlow but get the following error:

error: cannot find symbol variable parentclass_parent_id

The code looks (simplified) as follows:

class ParentClass
{
@Column
@PrimaryKey (autoincrement = true)
private long parent_id;

private ArrayList<ChildClass> childs;

@OneToMany(methods = {OneToMany.Method.ALL}, variableName = "childs")
public ArrayList<ChildClass> getMyChilds() {
    if (childs== null || childs.isEmpty()) {
        childs= (ArrayList<ChildClass>) SQLite.select()
                .from(Child.class)
                .where(Child_Table.parentclass_parent_id.eq(parent_id))
                .queryList();
    }
    return childs;
}
}

class ChildClass
{
@ForeignKey(references =

        {@ForeignKeyReference(columnName = "parentClassKey",

                foreignKeyColumnName = "parent_id")})

ParentClass parentClass;
}

Any idea what's wrong?


Solution

  • Add @Column(name = "parentclass_parent_id") to your primary key value.