我在 flutter 应用程序中使用 floor 作为 SQLite 抽象。
我想保存一个包含礼物列表的人,所以我创建了一个外键(如here所述)并将子
id
映射到父presents
,但是当我运行生成器时出现错误Column type is not supported for List<Present>
通过flutter packages pub run build_runner build
。
我有礼物和人作为实体。
@entity
class Present {
@PrimaryKey(autoGenerate: true)
int? id;
String name;
double? price;
Present({this.id, required this.name, this.price});
}
@Entity(tableName: 'Person', foreignKeys: [
ForeignKey(childColumns: ['id'], parentColumns: ['presents'], entity: Present)
])
class Person {
@PrimaryKey(autoGenerate: true)
int? id;
String name;
List<Present> presents;
Person({
this.id,
required this.name,
required this.presents,
});
}
我认为在底层,你不能使用复杂类型作为属性来建模关系。看看 https://github.com/pinchbv/floor/blob/develop/docs/entities.md ...这里只引用了普通的外键。仍然有一个开放的
@Relation
注释功能请求开放,但据我所知,它尚未实现。相反,您可能必须自己加载和映射关系。