Skip to content

Add a new Model to FluxC

Andrey edited this page Dec 15, 2023 · 5 revisions

Room

  • A model can be created in org.wordpress.android.fluxc.persistence.entity.
  • The model has to be registered in org.wordpress.android.fluxc.persistence::WCAndroidDatabase.
  • Make sure to add either manual or auto migration with a test in MigrationTests

WellSql (deprecated)

  • Create a new class in org.wordpress.android.fluxc.model, this new class should implements Identifiable, minimum Model sample:
@Table
public class TestModel implements Identifiable {
    @PrimaryKey
    @Column private int mId;

    // Post format attributes
    @Column private String mName;

    public int getId() {
        return mId;
    }

    public void setId(int id) {
        mId = id;
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }
}
  • Edit the WellSqlConfig class, and add a migration step for the new table (see other CREATE TABLE ... entries in the onUpgrade() method

  • If you add any test, make sure the WellSqlConfig is used in the test setup or create the new table yourself.