Using Room's @ForeignKey as @Entity parameter in Kotlin Using Room's @ForeignKey as @Entity parameter in Kotlin java java

Using Room's @ForeignKey as @Entity parameter in Kotlin


This is the way to provide the annotation you're looking for, with explicit arrays for the arguments, and no @ for the nested annotation's creation:

@Entity(tableName = "Foo",     foreignKeys = arrayOf(            ForeignKey(entity = Bar::class,                     parentColumns = arrayOf("someCol"),                     childColumns = arrayOf("someOtherCol"),                     onDelete = CASCADE)))

Since Kotlin 1.2, you can also use array literals:

@Entity(tableName = "Foo",    foreignKeys = [        ForeignKey(entity = Bar::class,                parentColumns = ["someCol"],                childColumns = ["someOtherCol"],                onDelete = CASCADE)])