如何在房间持久性库中使用外键

如何在房间持久性库中使用外键

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

问题描述

我正在使用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

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

07-24 10:26