Consider I have a model : Company 1 - N Person
I want to display a list of persons with their names and their company's name. But not every person has a company.
I order to avoid that every call to person.getCompany() results in a new SQL query so I was thinking about adding a join :
QueryBuilder<Person> queryBuilder = session.getPersonDao().queryBuilder();
queryBuilder.join(PersonDao.Properties.CompanyId, Company.class);
queryBuilder.list()
The problem is that I only get the persons with a company because the generated query uses JOIN which is equivalent to INNER JOIN. I think I would need LEFT JOIN to also get the persons without a company.
It doesn't seem GreenDAO supports LEFT JOIN right now. Is there another way to make the request without doing a raw query ?
For those who don't know how to do it with raw query:
String query = " LEFT JOIN COMPANY ON T.id = COMPANY.ID where SOME_CONDITIONS";
List<Person> persons = session.getPersonDao().queryRaw(query);
Greendao will insert SELECT T.COLUMN_1, ... T.COLUM_N from PERSON AS T part by itself.
So in query T is just alias name for Person table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With