多级继承是否可能是糖ORM?

时间:2017-11-22 15:56:31

标签: java android sqlite sugarorm

我正在使用Android应用程序并遇到了与Sugar ORM的障碍。

例如,假设我有这些类。

public class Animal extends SugarRecord {
  ...
  Animal() {
  }
  ...
}

public class Dog extends Animal {
  ...
  Dog () {
    super();
  }
  ...
}

public class Cat extends Animal {
  ...
  Cat () {
    super();
  }
  ...
}

现在很明显,狗和猫有很多共同之处,就像我正在使用的实际桌子一样。我的问题是,当我尝试制作狗或猫并对它们使用保存方法时,日志说它们是持久的,因为它们的查询不起作用,所以我不确定它们是否保存在其他表中

我尝试了以下方法,使用了所有不同类型的查询方法,但没有运气。

Dog dog = new Dog(...);
dog.save();

Cat cat = new Cat(...);
cat.save();

Animal dog = new Dog(...);
dog.save();

Animal cat = new Cat(...);
cat.save();

// THIS IS THE ONLY ONE THAT WORKS
Animal animal = new Animal(...);
animal.save();

// This only returns the ones saved "Animal animal = new Animal(...)"
Select.from(Animal.class).list();

// This returns nothing
Select.from(Dog.class).list();

// This returns nothing
Select.from(Cat.class).list();

使用我能够使用的迁移脚本 CREATE TABLE DOG(...) 爆炸并说DOG已经存在,这意味着正在创建表,只是没有填充或无法访问。

将新记录保存为Dog and Cat时,会打印出来 I/Sugar: Dog saved : 9 所以它应该把它保存成某种东西。

此外,在运行查询时,这是打印输出的内容 D/SQL Log: SQLiteQuery: SELECT * FROM DOG

任何想法,如果继承实际上与Sugar ORM一起使用,或者除了有2个单独的类,其中包含冗余数据之外还有它吗?或者,如果您有任何其他库,建议您查看以实现此目的。

谢谢。

0 个答案:

没有答案