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

Many-to-one does not work? #646

Closed
schoettl opened this issue Jul 23, 2016 · 1 comment
Closed

Many-to-one does not work? #646

schoettl opened this issue Jul 23, 2016 · 1 comment

Comments

@schoettl
Copy link

Hi, first, thank you for this nice and simple ORM library!

I noticed a problem in my project with a many-to-one relationship.

I basically have these classes:

class Person extends SugarRecord {
    private Group group;
    ...
}
class Group extends SugarRecord {
}

When I call new Person().save();, I get this error:

FATAL EXCEPTION: main
 Process: mypackage, PID: 9915
 android.database.sqlite.SQLiteException: near "GROUP": syntax error (code 1): , while compiling: INSERT OR REPLACE  INTO PERSON(GROUP,GENDER,ID,AGE_GROUP) VALUES (?,?,?,?)
     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
     at com.orm.SugarRecord.save(SugarRecord.java:280)
     at com.orm.SugarRecord.save(SugarRecord.java:416)
     ...

Note that this is a special case: group == null

According to the homepage, it should work: http://satyan.github.io/sugar/creation.html#why - am I wrong?

Notes:

  • It worked, before I changed Long groupId to Group group.
  • I incremented the db version number.
  • I deleted the db with deleteDatabase(name).
@schoettl
Copy link
Author

Oh, GROUP is a reserved word in SQL! My bad.

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

No branches or pull requests

1 participant