Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sugar ORM in Android: update a saved object in SQLite

I'm new to app development using SQLite and Sugar ORM on Android, and have tried to read through the Sugar ORM documentation, but didn't find anything for how to update a saved object in SQLite. Can I still save the object after changing its properties? something like:

Customer myCustomer = (Customer.find(Customer.class, "id = ?", id)).get(0);
myCustomer.setName("new name");
myCustomer.setAddress("new Address");
myCustomer.save(); // is this okay for updating the object?

the save() method won't create another new object while leaving the old entry untouched, right?

like image 926
TonyGW Avatar asked Nov 10 '14 02:11

TonyGW


2 Answers

Your code should update the row without issue.

From the docs - Update Entity:

Book book = Book.findById(Book.class, 1);
book.title = "updated title here"; // modify the values
book.edition = "3rd edition";
book.save(); // updates the previous entry with new values.
like image 85
Nick Avatar answered Oct 22 '22 02:10

Nick


It will update your entity. The Sugar ORM overwriting your existing e.g Name and updated it with "new name" after the save() method call.

like image 3
loose11 Avatar answered Oct 22 '22 03:10

loose11