Sugar ORM:将数据插入具有外键的表中

时间:2015-04-08 12:32:10

标签: android android-sqlite sugarorm

我在我的Android应用程序中使用Sugar ORM。我的数据结构为

public class Attendance extends SugarRecord<Attendance> {

Date logDateTime;
String Flag;
Shift shift;
...

public class Shift extends SugarRecord<Shift> {

String shiftName;
Date startTime, EndTime;
...

我在Shift表中有数据,但documentation在解释如何在考勤表中创建新行方面没什么帮助。

任何人都可以提供有关如何在考勤表中创建条目的示例代码,并引用Shift表。

谢谢。

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案..

        List<Shift> st1 = Shift.listAll(Shift.class);

     //should figure out the best way to link the reference key and array counter. 
     // If the PK of the master table is identity //or at least an integer
//this can be worked out easily.

selectedShift = st1.get(0);
    Attendance attendance = new Attendance();

    attendance.setShift(selectedShift);
    attendance.setFlag("E");
    attendance.setLogDateTime(new Date());
    attendance.save();

感谢。