roscopeco/ormdroid

Entity id and save

Opened this issue · 2 comments

What if I want to use the same ids used in my server ?
I create a Entity instance specifying my own id, then I save it, ORMDroid throws away my own id and replaces it by last_insert_rowid.
I'm stuck there.
I think I have to create a new field, like cloudId, and use this one when manipulating Entities... Is there any other work around ?

Thanks !

Maybe using this :
http://stackoverflow.com/questions/418898/sqlite-upsert-not-insert-or-replace/4330694#4330694
in the EntityMapping.insert(SQLiteDatabase db, Entity o)
And when entityInstance.isTransient() == true && entityInstance.getPrimaryKeyValue() != null do not query for the last_insert_rowid(); and return entityInstance.getPrimaryKeyValue(); instead.

What do you think @roscopeco ?

Internally, the presence of a primary key is used to determine whether the object is transient, so there'd have to be another mechanism for that. Also, how would this work with database constraints? I'm open to taking a look into it though...