Storing Data in Android with Room
Many to Many Relationship
Autoplay
Up next
Previous
About
Overview
In this lesson, we'll discuss what a many-to-many relationship is, and show how we can model a many-to-many relationship using Room
.
We'll create a many-to-many relationship between Users
and Tasks
. We'll walk through all of the steps required to create the entity and queries for adding, removing and querying a many-to-many relationship in the database.
Summary of Content:
- What a many-to-many relationship is and how they work
- What SQL join table is and why we need it
- Creating an entity for the join table
- Which primary and foreign keys we'll need for the join table entity
- How to insert into the join table, so that we can assign a task to a user
- Use of
OnConflictStrategy
to prevent adding duplicate data - How to query for all tasks, which also retrieves all of the assigned users
- How to query for all users, which also retrieves all of the assigned tasks
- How to join across multiple tables to retrieve all the data required
- How to model the types that will be retrieved from the database, using
@Embedded
annotation - How to transform the return type into something easier to work with
- How to convert null relations into an empty list so we don't have to think about nullability
Links:
Instructor
Links
Comments
Lessons in Storing Data in Android with Room
1. Introduction and Integration
01:35
2. Creating the Database

02:23
3. Defining an Entity

02:02
4. Custom SQL Table and Column Names

01:20
5. Creating the Data Access Object (DAO)

Pro
01:50
6. Inserting Entities with the @Insert Annotation

Pro
03:29
7. Reading data using the @Query Annotation

Pro
02:34
8. LiveData

Pro
03:00
9. Passing Parameters into a @Query

Pro
02:23
10. Deleting entities using the @Delete annotation

Pro
02:56
11. Updating an entity using the @Update annotation

Pro
02:32
12. Foreign Key Relationships

Pro
03:55
13. One to Many Relationships

Pro
04:28
14. @Relation annotation

Pro
04:05
15. Many to Many Relationship

Pro
11:25
16. TypeConverter

Pro
02:39
17. Database Migrations

Pro
05:29

Something went wrong
Lesson added to playlist
Create new playlist
Name can't be empty