Realm-java: RealmList is crazy

Created on 3 Nov 2018  路  7Comments  路  Source: realm/realm-java

WWW

O-Community T-Help

All 7 comments

Probably your VG has the same ID each time, so you are modifying the same object across the DB.

Obviously this is not evident from showing a partially formatted code snippet that does not resemble the issue template, nor does it actually contain the code that can reproduce your issue.

(i do not work for Realm btw, despite the contributor label)

Closing as this was answered on Stack Overflow

Hey - looks like you forgot to add a T:* label - could you please add one?

@rrreza Please understand that this repo is for tracking features and enhancements. Questions like yours really belong to Stack Overflow. This is also mentioned in the template you deleted when creating this issue.

If you think there is a problem with Realm please provide a working sample project we can look at.

That said when you are using copyToRealm it is copying the entire object replacing all fields. So why do you expect the old list to still be there when you explicitly do this: m_p.setVg(new RealmList<>(vgs.toArray(new VG[vgs.size()])));

If you only want to update some fields you should update them manually.

List<VG> vs=new ArrayList<>();
for(int i=0;i<10;i++){
    VG v=new VG();
    v.setId(i);
    v.setName(editText1.getText().toString()+i);

Of course it "replaces VG of all previous M_P`" you are setting the ID 0...10 for every single VG you create.

Primary key uniquely identifies the object so if you insert a new object with same ID, it will overwrite the existing object with the same ID

            Number currentMax = realm.where(VG.class).max("id");
            int nextid = 0;
            if (currentMax != null) {
                nextid = currentMax.intValue() + 1;
            }
            vg.setId(nextid);

@cmelchior guy deleted all his posts and edited his original post to WWW.

I think this can probably be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tloshi picture tloshi  路  3Comments

cmelchior picture cmelchior  路  3Comments

mithrann picture mithrann  路  3Comments

wezley98 picture wezley98  路  3Comments

Merlin1993 picture Merlin1993  路  3Comments