Reputation: 1349
How can define an auto increment primary key in Sugar model? Do Sugar automatically creates unique ID for each record
import com.orm.SugarRecord;
public class Customers extends SugarRecord {
int id; // this field must be auto increment primary key
String name;
String tel;
String mobile;
String address;
String create_date;
public Customers(){}
public Customers(int id, String name, String tel, String mobile, String address, String create_date){
this.id = id;
this.name = name;
this.tel = tel;
this.mobile = mobile;
this.address = address;
this.create_date = create_date;
}
}
Upvotes: 0
Views: 2111
Reputation: 921
You may create a custom table my annotating your class with "@Table", but you should create a long type of "id" for the ORM to work with. The best way would be to let sugar do all the work.
Sugar will create an id field (you do not need to include in your class) and you may access it using "getId()" something like:
Customers customer = Customers.findById(Customers.class, 1)
long customer_id = customer.getId();
Upvotes: 1