小编Kar*_*nga的帖子

使用Room在@Query结果中使用@Ignore字段

我有两个简单的locationhouses表。我希望能够获取location所有相关信息,并将其添加house到该查询中。该houseCount字段已标记,@Ignored因为我不希望保存此字段。但是,Room似乎无法像在指定为查询的返回对象类型的任何其他类中那样,使用该字段从查询中返回数据。

我的领域:

@Ignore
@ColumnInfo(name = EXTRA_COLUMN_LOCATION_HOUSE_COUNT)
public int houseCount;
Run Code Online (Sandbox Code Playgroud)

我的位置构造函数:

public Location(long id, String name, LatLng location, long defaultRent, Date synced, int houseCount) {...}
Run Code Online (Sandbox Code Playgroud)

我的查询:

SELECT locations.*, COUNT(DISTINCT houses.id) AS house_count FROM locations, houses WHERE locations.id = :id AND houses.location_id = :id
Run Code Online (Sandbox Code Playgroud)

警告:

Warning:(37, 14) The query returns some columns [house_count] which are not use by ug.karuhanga.logrealty.Models.Entities.Location. You can use @ColumnInfo annotation on the fields to specify the …
Run Code Online (Sandbox Code Playgroud)

android android-room

7
推荐指数
1
解决办法
1539
查看次数

标签 统计

android ×1

android-room ×1