Since grrendao doesn't implement QueryBuilder.join()
-methods at the moment, I think your solution is one of the best you can get right now, as it uses joins internally.
There are only minor drawbacks to it:
- you potentially query more tables than you actually need
- you have to iterate through a potentially large list
- you cannot use
listLazy()
Another way would be to use some query like this (presumed IsFriend
is an int-column
and myType
fits to ChatDao.Properties.type
:
Query<Chat> qc = chatDao.queryRawCreate(
" LEFT JOIN "+UserChatsDao.TABLENAME+" UC"+
" ON T."+ChatDao.Properties.id.columnName+"=UC."+UserChats.Properties.chatId.columnName+
" LEFT JOIN "+UserDao.TABLENAME+" U"+
" ON UC."+UserChats.Properties.userId.columnName+"=U."UserDao.Properties.id.columnName+
" WHERE U."UserDao.Properties.isFriend.columnName+"=?"+
" AND T."+ChatDao.Properties.type.columnName+"=?", 1, myType);
Or (probably less performant):
Query<Chat> qc = chatDao.queryRawCreate(
" , "+UserChatsDao.TABLENAME+" UC"+
" , "+UserDao.TABLENAME+" U"+
" WHERE T."+ChatDao.Properties.type.columnName+"=?"+
" AND U."+UserDao.Properties.isFriend.columnName+"=?"+
" AND T."+ChatDao.Properties.id.columnName+"=UC."+UserChats.Properties.chatId.columnName+
" AND U."UserDao.Properties.id.columnName+"=UC."+UserChats.Properties.userId.columnName, myType, 1);
Then you can use the desired list()
-methods:
qc.list();
qc.listLazy();
...