List<>

问题描述 投票:0回答:1

我在 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,
  });

}
flutter sqlite foreign-keys
1个回答
0
投票

我认为在底层,你不能使用复杂类型作为属性来建模关系。看看 https://github.com/pinchbv/floor/blob/develop/docs/entities.md ...这里只引用了普通的外键。仍然有一个开放的

@Relation
注释功能请求开放,但据我所知,它尚未实现。相反,您可能必须自己加载和映射关系。

© www.soinside.com 2019 - 2024. All rights reserved.