美洲虎Orm-自反关系

时间:2018-09-10 06:55:49

标签: orm dart

jaguar_orm支持自反关系吗?

我有一个Category类,它可以属于另一个Category:

class Category {
  /// constructor
  Category();
  Category.make(this.id, this.name);

  /// fields
  @PrimaryKey()
  int id;

  @Column(isNullable: false)
  String name;

  @BelongsTo(CategoryBean, isNullable: true, refCol: 'id')
  int parentCategoryId;

  /// database
//  String toString() => "Product($id, $name, $parentCategoryId)";
  String toString() => "Product($id, $name)";
}

当我尝试创建一个堆栈时,出现如下所示的堆栈溢出:

Exception while parsing field: id!
Stack Overflow
#0      _Uri._uriEncode (dart:core/runtime/liburi_patch.dart:34:3)
#1      _Uri._makePath.<anonymous closure> (dart:core/uri.dart:2116:23)
#2      ListIterable.join (dart:_internal/iterable.dart)
#3      _Uri._makePath (dart:core/uri.dart:2117:12)
#4      _SimpleUri.replace (dart:core/uri.dart:4358:19)
#5      urlOfElement (package:source_gen/src/utils.dart:87:11)
#6      _MirrorTypeChecker.isExactly (package:source_gen/src/type_checker.dart:264:49)
#7      _ListBase&Object&ListMixin.any (dart:collection/list.dart)
#8      TypeChecker.isAssignableFromType (package:source_gen/src/type_checker.dart:162:57)
#9      ParsedBean._makeField.<anonymous closure> (package:jaguar_orm_gen/src/parser/parser.dart:351:47)
#10     WhereIterator.moveNext (dart:_internal/iterable.dart)
#11     MappedIterator.moveNext (dart:_internal/iterable.dart:391:19)
#12     new List.from (dart:core/runtime/libarray_patch.dart:40:17)
#13     ParsedBean._makeField (package:jaguar_orm_gen/src/parser/parser.dart:472:34)
#14     ParsedBean._parseFields (package:jaguar_orm_gen/src/parser/parser.dart:325:21)
#15     ParsedBean.detect (package:jaguar_orm_gen/src/parser/parser.dart:74:5)
#16     ParsedBean.detect (package:jaguar_orm_gen/src/parser/parser.dart:85:56)

这会重复一段时间。

我需要做一些特别的事情来防止堆栈溢出吗?

1 个答案:

答案 0 :(得分:0)

您需要根据情况添加@HasOne或@HasMany装饰器。