Ara*_*ini 3 android primary-key sugarorm
我是第一次使用SugarORM,我有一个简单的问题.如何将一个实体设置为主键?例如,我需要这样的东西:
public class Student{
@PrimaryKey
private String studentId;
private String name;
}
Run Code Online (Sandbox Code Playgroud)
可能吗?谢谢.
目前无法指定主键.但从糖1.4开始,可以选择使用@Unique属性(https://github.com/satyan/sugar#sugarrecord):
public class Book extends SugarRecord {
@Unique
String isbn;
String title;
String edition;
/*...*/
public Book(String isbn, String title, String edition) {
this.isbn = isbn;
this.title = title;
this.edition = edition;
}
}
Run Code Online (Sandbox Code Playgroud)
它不是主键,但在许多情况下它做类似的工作(https://github.com/satyan/sugar#update-entity-based-on-unique-values):
Book book = new Book("isbn123", "Title here", "2nd edition")
book.save();
// Update book with isbn123
Book sameBook = new Book("isbn123", "New Title", "5th edition")
sameBook.update();
book.getId() == sameBook.getId();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3660 次 |
| 最近记录: |