How to join multiple instances of same object in Android Room?

前端 未结 3 702
北恋
北恋 2020-12-21 01:28

NOTE: I cannot use relation as we had performance issue which is not reproduced on direct join query.

Until I added target user and from group use

3条回答
  •  鱼传尺愫
    2020-12-21 01:46

    as mentioned Moayad .AlMoghrabi I should use table aliases. So I renamed LEFT JOIN chat_user to LEFT JOIN chat_user target_user. Note there is no AS between chat-user and target_user. (my mistake was that I tried to put it there). Behavior of prefixes is still a mystery to me as the prefix for chat_user works properly, but if I put the prefix to ChatUserRelationEntity then I receive unknown column error.

    SELECT * FROM message_item 
    LEFT JOIN block_item
        ON block_item.block_message_id = message_item.message_local_id
    LEFT JOIN chat_user_relation 
        ON chat_user_relation.chat_user_relation_chat_user_id = message_item.message_user_id
        AND chat_user_relation.chat_user_relation_chat_user_chat_id = :chatId
    LEFT JOIN chat_user target_user 
        ON target_user.chat_user_id = message_item.messages_target_user
    LEFT JOIN chat_user from_group_user 
        ON from_group_user.chat_user_id = message_item.messages_from_group_user
    WHERE message_item.message_chat_id = :chatId
    ORDER BY message_created_at ASC
    

提交回复
热议问题