Since grrendao does not currently implement QueryBuilder.join() methods, I think your solution is one of the best that you can get right now because it uses internal joins.
There are only minor flaws:
- you are potentially querying more tables than you really need
- you need to iterate over a potentially large list
- you cannot use
listLazy()
Another way would be to use such a query (suppose IsFriend matches int-column and myType matches 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 (possibly less productive):
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(); ...
source share