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 user
and corresponding
LEFT JOIN chat_user ON chat_user.chat_user_id = message_item.messages_target_user
LEFT JOIN chat_user ON chat_user.chat_user_id = message_item.messages_from_group_user
It worked well. But after addition, I can not figure out how to make those prefixes map in the query.
class ReadMessageEntity(
@Embedded
var message: MessageEntity,
@Embedded
var block: BlockEntity?,
@Embedded
var user: ChatUserRelationEntity,
@Embedded(prefix = "target_user_")
var targetUser: ChatUserEntity?,
@Embedded(prefix = "from_group_user_")
var fromGroupUser: ChatUserEntity?
)
This is which I'm trying to query:
@Transaction
@Query("""
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_id = message_item.message_user_id
LEFT JOIN chat_user ON chat_user.chat_user_id = message_item.messages_target_user
LEFT JOIN chat_user ON chat_user.chat_user_id = message_item.messages_from_group_user
WHERE message_item.message_chat_id = :chatId
ORDER BY message_created_at ASC
""")
fun getMessagesByChat(chatId: String): Single<List<ReadMessageEntity>>
The error:
e: error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (ambiguous column name: main.chat_user.chat_user_id)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…