java - Android DBFlow 一对多完整示例

标签 java android orm dbflow

我对如何在 DBFlow 中声明外键感到困惑。在 DBFlow(https://github.com/Raizlabs/DBFlow/blob/f2d90db39a4bf5ffcc0f22032ae20d5328b8d3c3/usage2/Relationships.md)的关系入门页面中,它有Queen 类的示例,但没有AntColony 类。

有没有人有包含Queen + Ant + Colony 类的完整示例?

谢谢

最佳答案

这是您想要的示例代码:

父表:

@Table(database = AppDatabase.class)
public class CafeWebContentCategories extends BaseModel {
    @PrimaryKey
    private int id;

    @Column
    private int categoryServerId;

    @PrimaryKey
    @Column
    public int cafeServerId;

    @Column
    private String title;

    @Column
    private boolean isAuto;

    public List<CafeWebChildContentCategories> subContentCategories;

    @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "subContentCategories")
    public List<CafeWebChildContentCategories> getMyChannelSubContentCategories() {
        if (subContentCategories == null || subContentCategories.isEmpty()) {
            subContentCategories = SQLite.select()
                    .from(CafeWebChildContentCategories.class)
                    .where(CafeWebChildContentCategories_Table.parentId.eq(cafeServerId))
                    .queryList();
        }
        return subContentCategories;
    }

    public CafeWebContentCategories() {
    }

    // setters and getters
}

子表:

@Table(database = AppDatabase.class)
public class CafeWebChildContentCategories extends BaseModel {
    @PrimaryKey
    @Column
    public int id;

    @Column
    public int categoryId;

    @Column
    @ForeignKey(tableClass = CafeWebContentCategories.class,
            references = @ForeignKeyReference(columnName = "parentId", foreignKeyColumnName = "cafeServerId"))
    public int parentId;

    @Column
    private String title;

    public CafeWebChildContentCategories() {
    }

    // setters and getters
}

有什么问题可以问我

关于java - Android DBFlow 一对多完整示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43739880/

相关文章:

java - 仅显示 JTable 中的一列

database - 如何保持代码库和数据库模式同步?

java - Tomcat 没有在跨域 jquery ajax 调用中接收自定义 header

java - 如何在 webapp 中实际连接事物

java - 当条件被 Action 监听器改变时中断 while 循环

java - 如何计算 map 跨度/缩放以在视口(viewport)中包含一组 GeoPoints?

android - 如何将搜索栏添加到 Exoplayer exo_playback_control_view.xml

Android 已弃用屏幕尺寸?

python - sqlalchemy/sql : cross model relationships, 从 'cousin' 模型获取信息

mysql - 使用 SQLAlchemy 创建表后,如何向其中添加其他列?