title: Android ORMLite - ForeignCollection child has null foreign field
body: <p>I'm currently stuck with the following situation;</p>
  
  <p>Basically I've got a Work class, which has a ForeignCollection of WorkTasks. 
  I'd like to simply receive all WorkTasks, linked to Work object. </p>
  
  <p>If I query for all WorkTasks, I do get a list of results but with 'work = null'. So it can't make any link to the correct Work object.
  Resulting in no results with querying for the work_id and an empty list in Work itself.</p>
  
  <p>I've seen examples and questions about this countless of times but apparently im missing out on something. </p>
  
  <p>Below is the code that im using which is relevant; </p>
  
  <p>The DatabaseHelper; </p>
  
  <pre><code>@Override
  public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
      try {
  
          applicantDao = DaoManager.createDao(connectionSource, Applicant.class);
          educationDao = DaoManager.createDao(connectionSource, Education.class);
          workDao = DaoManager.createDao(connectionSource, Work.class);
          workTaskDao = DaoManager.createDao(getConnectionSource(), WorkTask.class);
          onlinePersonDao = DaoManager.createDao(connectionSource, OnlinePerson.class);
          institutionDao = DaoManager.createDao(connectionSource, Institution.class);
          lessonDao = DaoManager.createDao(connectionSource, Lesson.class);
  
          TableUtils.createTable(connectionSource, Applicant.class);
          TableUtils.createTable(connectionSource, Education.class);
          TableUtils.createTable(connectionSource, Work.class);
          TableUtils.createTable(connectionSource, Institution.class);
          TableUtils.createTable(connectionSource, Lesson.class);
          TableUtils.createTable(connectionSource, OnlinePerson.class);
          TableUtils.createTable(connectionSource, Reference.class);
          TableUtils.createTable(connectionSource, WorkTask.class);
  
  [....]
  
   public Dao&lt;WorkTask, Integer&gt; getWorkTaskDao() {
      if (null == workTaskDao) {
          try {
              workTaskDao = getDao(WorkTask.class);
          } catch (java.sql.SQLException e) {
              e.printStackTrace();
          }
      }
      return workTaskDao;
  }
  </code></pre>
  
  <p>The database manager:</p>
  
  <pre><code>public List&lt;Experience&gt; getAllWork() {
          List&lt;Experience&gt; exp = null;
          try {
              exp = getHelper().getWorkDao().queryForAll();
          } catch (SQLException e) {
              e.printStackTrace();
          }
          return exp;
      }
  
      public List&lt;WorkTask&gt; getAllWorkTask() {
          List&lt;WorkTask&gt; workTask = null;
          try {
              workTask = getHelper().getWorkTaskDao().queryForAll();
          } catch (SQLException e) {
              e.printStackTrace();
          }
          return workTask;
      }
  
  public List&lt;WorkTask&gt; getWorkTaskByWorkId(int workId) {
          List&lt;WorkTask&gt; workTasks = null;
          try {
              workTasks = getHelper().getWorkTaskDao().queryForEq("work_id", workId);
          } catch (SQLException e) {
              e.printStackTrace();
          }
          return workTasks;
      }
  
  public void addWork(Collection&lt;Work&gt; jobs) {
          try {
              for (Experience work : jobs) {
                  Work w = (Work) work;
                  // Add nested child first
                  this.addInstitution(w.institution);
                  this.addWorkTask(w.tasks);
  
                  getHelper().getWorkDao().createOrUpdate(w);
              }
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  
      public void addWorkTask(Collection&lt;WorkTask&gt; worktasks) {
          try {
              for (WorkTask wt : worktasks) {
                  getHelper().getWorkTaskDao().createOrUpdate(wt);
              }
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>The list from the work model (gets a pre-filled id from an abstract parent):</p>
  
  <pre><code>@ForeignCollectionField(eager = true)
      @SerializedName("tasks")
      public Collection&lt;WorkTask&gt; tasks;
  
      public ArrayList&lt;WorkTask&gt; getTasks(){
          ArrayList&lt;WorkTask&gt; taskList = new ArrayList&lt;WorkTask&gt;();
          Iterator iterator = tasks.iterator();
          while(iterator.hasNext()){
              WorkTask task = (WorkTask) iterator.next();
                      taskList.add(task);
  
          }
          return taskList;
      }
  </code></pre>
  
  <p>The WorkTask :</p>
  
  <pre><code>public class WorkTask {
  
      /**
       * Auto-incremented id for the ORMLite-SQLite database
       */
      @DatabaseField(generatedId = true)
      public int id;
  
      /**
       * Foreign field id for the ORMLite-SQLite database
       */
      @DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true, columnName = "work_id")
      public Work work;
  </code></pre>
  
  <p>And finally all the things that are failing me: </p>
  
  <pre><code>        ArrayList&lt;WorkTask&gt; tasks_iterated = work.getTasks();
  
          ArrayList&lt;WorkTask&gt; tasks_id = (ArrayList&lt;WorkTask&gt;) DatabaseManager.getInstance()
                  .getWorkTaskByWorkId(work.id);
  
          ArrayList&lt;WorkTask&gt; tasks = (ArrayList&lt;WorkTask&gt;) DatabaseManager.getInstance().getAllWorkTask();
  </code></pre>
  
  <p>This eventually leaves me with:</p>
  
  <p>tasks_iterated = empty<br />
  tasks_id = empty<br />
  tasks = a full list of my tasks but all with the attribute 'work = null' so I can't place them to the correct Work object. </p>