Update entire object with DBFlow

409 views Asked by At

I am using DBFlow in my Android project and I would like to know if there is a way to update the entire object instead of specifying each column as shown below

// Native SQL wrapper
SQLite.update(Ant.class)
  .set(Ant_Table.type.eq("other"))
  .where(Ant_Table.type.is("worker"))
  .and(Ant_Table.isMale.is(true))
  .async()
  .execute(); // non-UI blocking

From the guide https://agrosner.gitbooks.io/dbflow/content/SQLiteWrapperLanguage.html

The 'Set' part of the Update supports different kinds of values:

  1. ContentValues -> converts to key/value as a SQLOperator of is()/eq()
  2. SQLOperator, which are grouped together as part of the SET statement.

Based on this, I tried to pass in a ContentValues into the set method

// Native SQL wrapper
SQLite.update(Ant.class)
  .set(contentValues)
  .where(Ant_Table.type.is("worker"))
  .and(Ant_Table.isMale.is(true))
  .async()
  .execute(); // non-UI blocking

and I get a compile error

set (com.raizlabs....SQLOperator...) in Update cannot be applied 
to (android.content.ContentValues)
1

There are 1 answers

0
Josef Adamcik On BEST ANSWER

You need to call it like this:

SQLite.update(Ant.class)
  .set().conditionValues(contentValues)
  .where(Ant_Table.type.is("worker"))
  .and(Ant_Table.isMale.is(true))
  .async()
  .execute(); 

It's not clear from the documentation niether from the source code but it should work this way.