public void testForeignKeyModel() {

    Delete.tables(ForeignInteractionModel.class, ParentModel.class);

    ForeignInteractionModel foreignInteractionModel = new ForeignInteractionModel();
    ParentModel parentModel = new ParentModel();
    parentModel.setName("Test");
    parentModel.type = "Type";
    parentModel.save();
    assertTrue(parentModel.exists());

    foreignInteractionModel.setTestModel1(parentModel);
    foreignInteractionModel.setName("Test2");
    foreignInteractionModel.save();

    assertTrue(foreignInteractionModel.exists());

    assertTrue(foreignInteractionModel.testModel1.exists());

    foreignInteractionModel =
        new Select()
            .from(ForeignInteractionModel.class)
            .where(ForeignInteractionModel_Table.name.is("Test2"))
            .querySingle();
    assertNotNull(foreignInteractionModel);
    assertNotNull(foreignInteractionModel.testModel1);
    TestModel1 testModel11 = foreignInteractionModel.getTestModel1();
    assertNotNull(parentModel);
    assertEquals("Test", testModel11.getName());

    Delete.tables(ForeignInteractionModel.class, ParentModel.class);
  }
Example #2
0
  @Test
  public void testCipherModel() {
    Delete.table(CipherModel.class);

    CipherModel model = new CipherModel();
    model.name = "name";
    model.save();

    assertTrue(model.exists());

    CipherModel retrieval =
        SQLite.select()
            .from(CipherModel.class)
            .where(CipherModel_Table.name.eq("name"))
            .querySingle();
    assertTrue(retrieval.id == model.id);

    Delete.table(CipherModel.class);
  }