Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use satyan's Sugar ORM with @Table annotation

Im very statisfied with SugarOrm for Android, but I ran into an issue. I'm using it with GSON for Json serializations and I want to get rid of SugarRecord's id attribute. I know I should use @Table annotation and later exclude specific field from serialization using @Expose, but after annotating class with @Table I cannot use .save(), delete(),... methods on the object, as it is the case extending SugarRecord. I don't know how to persist objects using @Table annotation.

I found the documentation here very limited.

like image 1000
urgas9 Avatar asked Dec 15 '22 08:12

urgas9


1 Answers

The document hasn't been updated for the annotation based persistence yet. The methods save(), delete() will be available as static methods on SugarRecord class.

So instead of doing this:

object.save()

You'd be doing this:

SugarRecord.save(object)

Check out some tests here to understand better. https://github.com/satyan/sugar/tree/master/example/src/test/java/com/example/sugartest

like image 119
Satya Avatar answered Jan 20 '23 07:01

Satya