我有以下型号:
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返回null
答案 0 :(得分:3)
由于引擎被定义为汽车中的外键,因此您只需使用如下所示的查询。
new Select().from(Car.class)
.where(Condition.column(Car$Table.ENGINE_ENGINE)
.is([specific_engine_id])
.querySingle();