如何在房间持久性库中使用外键 [英] how to use foreign key in Room persistence library

查看:70
本文介绍了如何在房间持久性库中使用外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android中的房间持久性库,如果有人可以帮助我使用外键,以及如何使用外键获取数据,我将不胜感激.

I am working with room persistence library in android, i would appreciate if someone can help me in using foreign key, how to get data by using foreign key.

推荐答案

仅总结以上文章,以供将来的读者使用:

Just to summarize the above posts for future readers:

Kotlin中的外键语法为

The foreign key syntax in Kotlin is

@Entity(foreignKeys = arrayOf(ForeignKey(entity = ParentClass::class,
                    parentColumns = arrayOf("parentClassColumn"),
                    childColumns = arrayOf("childClassColumn"),
                    onDelete = ForeignKey.CASCADE)))

Java中的外键语法为:

The foreign key syntax in Java is:

@Entity(foreignKeys = @ForeignKey(entity = ParentClass.class,
    parentColumns = "parentClassColumn",
    childColumns = "childClassColumn",
    onDelete = ForeignKey.CASCADE))

有关更多信息,请参阅官方文档. https://developer.android.com/reference/android/arch/persistence/room/ForeignKey.html

You can refer to the official documentation for more information. https://developer.android.com/reference/android/arch/persistence/room/ForeignKey.html

这篇关于如何在房间持久性库中使用外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆