In my application This design relationship: And I want to select at least one user as a friend for all chats.
Basically, I want to execute the following query: \
SELECT c.* from CHAT C, USER u, userchats uc = myType 1 = uc.chatid< c8/>= Uc.userid
I didn't try to find the Greendao library to execute this way, I hope someone can help me this.
Edit:
This is what I have been up to now:
list<userschats> list =Userschatsdao.querydeep ("WHERE T0."+ UserDao.Properties.isFriend.collumnName +" = ? "+"and T1."+ ChatDao.Properties.type.collumName +" = ?", NewString[] {"1", MyType});if(List! =NULL&& list.isempty () = =false) {List<Chat> chats =NewArraylist<chat>(); for(Userschats link:list) {Chats.add (Link.getchat ()); }}Workaround 1:
Because Grrendao will not execute QueryBuilder.join() -the current method, I think your solution is the best one that you can now find, and it uses the joins internally.
There is only a small disadvantage to it:
- You may be querying more tables than you actually need
- You're going to traverse a potentially huge list of
- You cannot use
listLazy()
Another way to do this is to use a few queries like this (assuming IsFriend int-column and myType fitting 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 performance, etc.):
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 required list() -method:
Qc.list (); Qc.listlazy ();
Android Greendao deep Query n:m relationship