如何在 DBFlow 中进行复杂查询?
How to make a complex query in DBFlow?
我有以下型号:
class Car {
@Column(columnType = Column.PRIMARY_KEY_AUTO_INCREMENT, name = "id")
long id;
@Column(columnType = Column.FOREIGN_KEY, references = {@ForeignKeyReference(columnName = "engine", columnType = String.class, foreignColumnName = "id")})
Engine engine;
// .. other columns
}
class Engine {
@Column(columnType = Column.PRIMARY_KEY_AUTO_INCREMENT, name = "id")
long id;
// .. other columns
}
我想查询具有特定引擎 ID 的汽车。
Engine engine = new Select().from(Engine.class).where(Condition.column(Engine$Table.ID).is(engineId).querySingle();
Car car = new Select().from(Car.class).where(Condition.column(Engine$Table.ENGINE).is(engine).querySingle();
虽然找到了引擎,但 Car returns null
由于引擎被定义为汽车中的外键,您可以简单地使用如下所示的查询。
new Select().from(Car.class)
.where(Condition.column(Car$Table.ENGINE_ENGINE)
.is([specific_engine_id])
.querySingle();
我有以下型号:
class Car {
@Column(columnType = Column.PRIMARY_KEY_AUTO_INCREMENT, name = "id")
long id;
@Column(columnType = Column.FOREIGN_KEY, references = {@ForeignKeyReference(columnName = "engine", columnType = String.class, foreignColumnName = "id")})
Engine engine;
// .. other columns
}
class Engine {
@Column(columnType = Column.PRIMARY_KEY_AUTO_INCREMENT, name = "id")
long id;
// .. other columns
}
我想查询具有特定引擎 ID 的汽车。
Engine engine = new Select().from(Engine.class).where(Condition.column(Engine$Table.ID).is(engineId).querySingle();
Car car = new Select().from(Car.class).where(Condition.column(Engine$Table.ENGINE).is(engine).querySingle();
虽然找到了引擎,但 Car returns null
由于引擎被定义为汽车中的外键,您可以简单地使用如下所示的查询。
new Select().from(Car.class)
.where(Condition.column(Car$Table.ENGINE_ENGINE)
.is([specific_engine_id])
.querySingle();