Skip to content

Instantly share code, notes, and snippets.

@parthdesai1208
Last active February 8, 2023 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parthdesai1208/6544217055cd82caa3a48e601fc225c3 to your computer and use it in GitHub Desktop.
Save parthdesai1208/6544217055cd82caa3a48e601fc225c3 to your computer and use it in GitHub Desktop.
Room
//one-to-many relation
@Entity(tableName = "TicketGroup")
data class TicketGroup(
@PrimaryKey(autoGenerate = false)
val groupId: Int,
val groupName: String,
)
@Entity(tableName = "Ticket")
data class Ticket(
@PrimaryKey(autoGenerate = false)
val ticketId: Int,
val ticketGroupId: Int,
val ticketIssue: String,
val ticketName: String,
val ticketPrice: Long
)
data class TicketGroupWithTickets(
@Embedded val ticketGroup: TicketGroup,
@Relation(
parentColumn = "groupId",
entityColumn = "ticketGroupId"
)
val ticketList : List<Ticket>
)
@Transaction
@Query("SELECT * FROM TicketGroup")
suspend fun getTicketGroupWithTickets(): List<TicketGroupWithTickets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment