Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding capability to specify primary key #78

Closed
wants to merge 3 commits into from

Conversation

nickdjones
Copy link
Contributor

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.

Usage:

public class Book extends SugarRecord<Book> {
    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;
    }

Example:

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

@whoshuu
Copy link
Collaborator

whoshuu commented Jul 4, 2014

I'd like to get some version of this in the codebase. Can you explain:

  1. Why you are adding to the .gitignore file?
  2. Why you make id public instead of protected?

@@ -91,31 +91,25 @@ void save(SQLiteDatabase db) {
if (!"id".equalsIgnoreCase(column.getName())) {
if (columnType.equals(Short.class) || columnType.equals(short.class)) {
values.put(columnName, (Short) columnValue);
}
else if (columnType.equals(Integer.class) || columnType.equals(int.class)) {
} else if (columnType.equals(Integer.class) || columnType.equals(int.class)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep style changes separate from feature additions.

@nickdjones
Copy link
Contributor Author

I added a .gitignore file because IDEs create a build folder that needs excluding.

You're right it should be protected rather than public.

@whoshuu
Copy link
Collaborator

whoshuu commented Jul 4, 2014

Which IDE are you using? I'm using Eclipse and it doesn't create any of those files you're adding to the .gitignore.

@nickdjones
Copy link
Contributor Author

Android Studio, which is superseding Eclipse as the recommended IDE for android development. I don't see how adding 2 lines to the ignore file is doing any harm?

@whoshuu
Copy link
Collaborator

whoshuu commented Jul 4, 2014

Gotcha. Thanks for the heads up.

On Jul 4, 2014, at 7:30 AM, ItsNotWorking notifications@github.com wrote:

Android Studio, which is superseding Eclipse as the recommended IDE for android development.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants