0

I have three tables Notes, Tags and join table with foreign keys of Note and Tag called NoteTagJoin, but how can I return Note with all Tags as one response?

Here is query to get Note and Tags:

SELECT n.*,t.* FROM notes n INNER JOIN note_tag_join nt ON n.entryId = nt.noteId INNER JOIN tags t ON t.tagId = nt.tagId WHERE n.entryId =:noteId

And here is response class which has to hold note and list of tags:

data class NoteResponse(
    @Embedded
    var note: Note? = null,
    @Relation(parentColumn = "entryId", entityColumn = "tagId", entity = Tag::class)
    var tags: List<Tag>? = null
)

But tags list is empty on response just note is there, I know for sure that Tags and Note exists in db and Join table has right foreign keys because all other queries works so my guess is that Query is wrong or NoteResponse class is wrong because I use annotation @Relation which I don't need, but if I don't add @Relation annotation on tags it throws error that room doesn't know what is this list so how to do it? I can't find any references for this, documentation only mentions embedding one class in POJO but no examples for Lists and all similar posts talks only about inserting list.

LeTadas
  • 3,436
  • 9
  • 33
  • 65
  • Hey can you please help on this: https://stackoverflow.com/questions/50372487/android-room-database-file-is-empty – KKSINGLA May 28 '18 at 13:53

1 Answers1

0

please see my realization of many-to-many relationship CinemaActorJoinDao

You can instead my code , replace with your , if you have any question , i will try ask to you :)

Saaanty
  • 195
  • 8