Skip to content

Instantly share code, notes, and snippets.

@deepanshu42
Last active April 23, 2020 17:25
Show Gist options
  • Save deepanshu42/65988d6655d52e51d71969e1ea3cfa3f to your computer and use it in GitHub Desktop.
Save deepanshu42/65988d6655d52e51d71969e1ea3cfa3f to your computer and use it in GitHub Desktop.
One-To-One Relationship Example
@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