Android: SugarORM 或条件
Android: SugarORM Or condition
我正在使用 SugarORM。
选择代码:
String action = "date_int ASC";
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("A")).orderBy(action).list();
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("B")).orderBy(action).list();
问题:
上面得到的列表要么只有A类,要么只有B类。
从官网只能生成AND条件A和B如下:
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("A"), Condition.prop("category").eq("B")).orderBy(action).list();
我怎样才能得到一个列表,一个类别的组合列表 (A 或 B),并按 "date_int ASC" 的顺序排列?
谢谢!
您可以为此使用 whereOr()
:
record_list = Select.from(Records_records.class).whereOr(Condition.prop("category").eq("A"), Condition.prop("category").eq("B")).orderBy(action).list();
它是 where()
使用的默认 AND 的 OR 对应物。
它没有记录在案,但您可以在 source:
中找到它
@Test
public void testWhereOr(){
Select where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"));
assertEquals("(test = ? )", where.getWhereCond());
assertEquals(1, where.getArgs().length);
assertEquals("satya", where.getArgs()[0]);
where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2));
assertEquals("(test = ? OR prop = ? )", where.getWhereCond());
assertEquals(2, where.getArgs().length);
assertEquals("satya", where.getArgs()[0]);
assertEquals("2", where.getArgs()[1]);
}
我正在使用 SugarORM。
选择代码:
String action = "date_int ASC";
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("A")).orderBy(action).list();
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("B")).orderBy(action).list();
问题:
上面得到的列表要么只有A类,要么只有B类。
从官网只能生成AND条件A和B如下:
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("A"), Condition.prop("category").eq("B")).orderBy(action).list();
我怎样才能得到一个列表,一个类别的组合列表 (A 或 B),并按 "date_int ASC" 的顺序排列?
谢谢!
您可以为此使用 whereOr()
:
record_list = Select.from(Records_records.class).whereOr(Condition.prop("category").eq("A"), Condition.prop("category").eq("B")).orderBy(action).list();
它是 where()
使用的默认 AND 的 OR 对应物。
它没有记录在案,但您可以在 source:
中找到它@Test
public void testWhereOr(){
Select where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"));
assertEquals("(test = ? )", where.getWhereCond());
assertEquals(1, where.getArgs().length);
assertEquals("satya", where.getArgs()[0]);
where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2));
assertEquals("(test = ? OR prop = ? )", where.getWhereCond());
assertEquals(2, where.getArgs().length);
assertEquals("satya", where.getArgs()[0]);
assertEquals("2", where.getArgs()[1]);
}