Last active
April 23, 2020 17:25
-
-
Save deepanshu42/65988d6655d52e51d71969e1ea3cfa3f to your computer and use it in GitHub Desktop.
One-To-One Relationship Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
data class User( | |
@PrimaryKey val userId: Long, | |
val name: String, | |
val age: Int | |
) | |
@Entity(foreignKeys = @ForeignKey(entity = User.class, | |
parentColumns = "userId", | |
childColumns = "userOwnerId", | |
onDelete = CASCADE)) | |
data class Library( | |
@PrimaryKey val libraryId: Long, | |
val title: String, | |
val userOwnerId: Long | |
) | |
data class UserAndLibrary( | |
@Embedded val user: User, | |
@Relation( | |
parentColumn = "userId", | |
entityColumn = "userOwnerId" | |
) | |
val library: Library | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment