Room Embedding @Embedded

Something I just discovered is that @Embedded​ fields in Room entities can themselves contain @Embedded fields. For example:

data class Post(
    @Embedded
    val media: Media
)

data class Media(
    @Embedded
    val metadata: Metadata
)

data class Metadata(
    val resolution: String
)

works as you would expect, with resolution being pulled up to the Post entity table. Not sure how deeply @Embedded you can go, or if there are any performance consequences to this, but a neat trick!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s