How to use a foreign key in a number storage library

I work with persistence library in android, I would appreciate if someone could help me in using a foreign key, how to get data using a foreign key.

+12
source share
2 answers

There is a good lesson I used:

https://medium.com/@tonyowen/room-entity-annotations-379150e1ca82

It also provides information on: @embeded, @ignore,@ColumnInfo

When we use a foreign key, be sure to put it onDelete = ForeignKey.CASCADEthis way, if you delete the data, this will also remove the dependency. This way you will not have false data or data that is never used

+5
source

:

Kotlin

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

Java:

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

. https://developer.android.com/reference/android/arch/persistence/room/ForeignKey.html

0

Source: https://habr.com/ru/post/1689896/


All Articles