Android Room map sub select result to a non column parameter
Android Room map sub select result to a non column parameter
我有
@Entity
public class Tag {
@PrimaryKey(autoGenerate = true)
private long id;
@ColumnInfo(name = "name")
private String name;
@Ignore
private int totalRecords;
}
和
@Query("SELECT *) FROM Tags ORDER BY importance DESC, name ASC")
LiveData<List<Tag>> getAll();
我想 select 计数来自花药 table 的标签并将其映射到 'totalRecords'
所以,我的查询变成了
@Query("SELECT *, (SELECT count(id) from RecordingAndTags where tagId=t.id) as totalRecords FROM Tags t ORDER BY importance DESC, name ASC")
LiveData<List<Tag>> getAll();
您可能已经猜到它失败了
The query returns some columns [totalRecords] which are not use by com.myapp.entities.Tag. You can use @ColumnInfo annotation on the fields to specify the mapping.
所以我已经将我的 'totalRecords' 修改为
@ColumnInfo(name = "totalRecords")
@Ignore
private int totalRecords;
不幸的是,它也没有用,并因同样的警告而失败。
我错过了什么吗?我做不到吗?
这似乎不再是 1.1.0-beta2
的问题
我有
@Entity
public class Tag {
@PrimaryKey(autoGenerate = true)
private long id;
@ColumnInfo(name = "name")
private String name;
@Ignore
private int totalRecords;
}
和
@Query("SELECT *) FROM Tags ORDER BY importance DESC, name ASC")
LiveData<List<Tag>> getAll();
我想 select 计数来自花药 table 的标签并将其映射到 'totalRecords' 所以,我的查询变成了
@Query("SELECT *, (SELECT count(id) from RecordingAndTags where tagId=t.id) as totalRecords FROM Tags t ORDER BY importance DESC, name ASC")
LiveData<List<Tag>> getAll();
您可能已经猜到它失败了
The query returns some columns [totalRecords] which are not use by com.myapp.entities.Tag. You can use @ColumnInfo annotation on the fields to specify the mapping.
所以我已经将我的 'totalRecords' 修改为
@ColumnInfo(name = "totalRecords")
@Ignore
private int totalRecords;
不幸的是,它也没有用,并因同样的警告而失败。
我错过了什么吗?我做不到吗?
这似乎不再是 1.1.0-beta2