Search code examples
javaandroidandroid-sqlitegreendaoandroid-storm

Android SQLite Query with foreign key using stORM or an alternative


I have the following models

categories(id, name)
places(id, name, category_id)

i have a list view which displays Content based on the categories the user wants to see.

Data for Categories

1, River
2, Hill Station
3, Wild Life
4, Temples

If the user wants to see places of only category_id = 2 and 4.

How can i do a query to the database to give back a list of places which have category_id = 2 and 4.

I am using stORM library for the Database.

They have the following functions to do a query.

dao.listAll();
dao.listByExample(exampleObj);

Solution

  • If you switch to greenDAO, you can use a QueryBuilder, which supports IN and the likes: http://greendao-orm.com/documentation/queries/