Search code examples
androidsqldatabasedbflow

DBFlow select where COLUMN in List?


I am trying to query my database for all models with primary keys in a list. This is my query (idsList is an ArrayList containing integers):

new Select().from(PostModel.class)
    .where(Condition.column(PostModel$Table.ID).in(0, idsList))
    .async().queryList(listener);

But Android Studio highlights the where condition, stating

"Cannot resolve method 'where(com.raizlabs.android.dbflow.sql.builder.Condition.In)"

So is Condition.In not considered a condition? How can I query all Models with primaryKey in an ArrayList?

I am using DBFlow 2.0. I can also use a regular SQL query String as a substitute, but I am not that versed in SQL, so if you could provide an SQL query String for my problem, that would be a possible workaround.


Solution

  • DBFlow v3.x now allows you to pass a collection to Condition.in()

    List<String> ids = new ArrayList<>();
    
    Condition.In in = Condition.column(Tree_Table.ID.getNameAlias()).in(ids);
    
    long count = new Select().count().from(Tree.class)
            .where(in)
            .count();