ActiveAndroid icon indicating copy to clipboard operation
ActiveAndroid copied to clipboard

Model data is automatically updated after called "new Select()"

Open cashow opened this issue 9 years ago • 2 comments

After tracking down some bugs in my project, I find out that datas querying from my database will be automatically updated when "new Select()" is called. Code below shows what I am talking about.

private List<TestObject> testList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    test();
}

private void test(){
    testList = new Select().from(TestObject.class).execute();
    print("log 0");
    for (int i = 0; i < testList.size(); i++) {
        TestObject object = testList.get(i);
        object.name += " hello";
    }
    print("log 1");
    int count = new Select().from(TestObject.class).execute().size();
    print("log 2");
}

private void print(String text){
    for (int i = 0; i < testList.size(); i++) {
        Log.d("test", text + " : " + testList.get(i).name);
    }
}

Log shows that datas in testList has been automatically updated after "new Select()":

log 0 : name1
log 0 : name2
log 0 : name3
log 1 : name1 hello
log 1 : name2 hello
log 1 : name3 hello
log 2 : name1
log 2 : name2
log 2 : name3

Is this some kind of bug? Is it wrong to change value of model data without calling "save()"?

cashow avatar Mar 14 '16 15:03 cashow

@cashow have the same issue? Did you solve it?

lectricas avatar Jan 27 '17 13:01 lectricas

This might be a bug or a feature, but that's beyond the point. Please take a look at 50d3934 and also c1d66ef.

saulojg avatar May 04 '17 22:05 saulojg