satyan/sugar — pull request #78 by ItsNotWorking (2014-03-28 14:09:17+00:00)
Title: Adding capability to specify primary key

This update allows the user to override the auto-generated primary key with one of their own. Useful for when using Sugar to synchronise data with another source.

Example usage:

public class Book extends SugarRecord {
public String name;

public Book(String name) {
this.name = name;
}

// Extra constructor to set id is not a requirement
// User can continue to use Sugar without changing code
public Book(Long id, String name) {
this.id = id;
this.name = name;
}

Usage:

Book autoBook = new Book("This book will get a generated ID like normal")
autoBook.save()
Book saved : 1

Book manualBook = new Book(99L, "This book has its ID specified manually")
manualBook.save()
Book saved : 99