【问题标题】:Sugar ORM: Insert data into table having foriegn keySugar ORM:将数据插入具有外键的表中
【发布时间】:2015-04-08 12:32:10
【问题描述】:

我在我的安卓应用中使用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 表的条目。

谢谢。

【问题讨论】:

    标签: android android-sqlite sugarorm


    【解决方案1】:

    好的,我想出了一个解决方案..

            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();
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      相关资源
      最近更新 更多