Android Greendao deep Query n:m relationship

Source: Internet
Author: User

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 uselistLazy()

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.