Using 'Join' and 'WhereOr' between Properties of more tables

12 views
Skip to first unread message

Ioana Catalina E

unread,
Dec 19, 2017, 5:51:32 AM12/19/17
to greenDAO
Hello! I have a situation in which I want to apply an OR operation after creating two JOINS. My conditions are not related only to one table but to two. I need to verify FloorId (from Floor table) and  TenantName & TenantOwner (from Tenant table)

I have a Table TenantOrder with a foreign key tenant_id corresponding to the primary id of Tenant table which also has another foreign key floor_id towards a Floor table.

So I create a queryBuilder from TentantOrderDao, then a join to join it with Tenant. After that I use the created join to make another one with Floor. The problem is I don't know how to create the WhereOr condition... 

QueryBuilder<TenantOrder> queryBuilder = tenantOrderDao.queryBuilder();
Join join_tenant = queryBuilder.join(TenantOrderDao.Properties.TenantId, Tenant.class);
queryBuilder.join(join_tenant, TenantDao.Properties.FloorId, Floor.class, FloorDao.Properties.Id);
queryBuilder.whereOr(TenantDao.Properties.TenantName.like("%" + query + "%'"),
TenantDao.Properties.OwnerName.like("%" + query + "%'"), FloorDao.Properties.ShortName.like("%" + query + "%')"));


The problem is I get an error saying that TenantName is not part of TenantOrderDao. I understand that my queryBuilder works with the properties of TenantOrder but how could I use in the same query fields from both Tenant and Floor ? I also used this variation, which complains about TenantName not being part of FloorDao.

QueryBuilder<TenantOrder> queryBuilder = tenantOrderDao.queryBuilder();
Join join_tenant = queryBuilder.join(TenantOrderDao.Properties.TenantId, Tenant.class);
queryBuilder.join(join_tenant, TenantDao.Properties.FloorId, Floor.class, FloorDao.Properties.Id).whereOr(TenantDao.Properties.TenantName.like("%" + query + "%'"),
TenantDao.Properties.OwnerName.like("%" + query + "%'"), FloorDao.Properties.ShortName.like("%" + query + "%')"));

Any help would be highly appreciated!
Reply all
Reply to author
Forward
0 new messages