2016-05-06 3 views
0

Sugarモデルで自動インクリメントプライマリキーをどのように定義できますか? ドゥ砂糖は自動的にあなたは私が「@Table」であなたのクラスに注釈を付けるカスタムテーブルを作成することも砂糖ormの自動インクリメントプライマリキー

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; 
    } 
} 
+0

回答します。https:// githubの.com/satyan/sugar/issues/593 – msoa

答えて

1

レコードごとに固有のIDを作成しますが、あなたはORMはで動作するため、「ID」のロングタイプを作成する必要があります。最善の方法は、砂糖にすべての仕事をさせることです。

シュガー idフィールドを作成します(あなたのクラスに含める必要はありません)、あなたが使用してアクセス可能 "のgetId()" 何かのように:

Customers customer = Customers.findById(Customers.class, 1) 
long customer_id = customer.getId(); 
関連する問題