在我的模型中,Author有很多Book。是否可以将每个作者的书籍数量作为临时属性?
这是我尝试过的,但它说:
NoSuchMethodError:在 null 上调用了 getter 'length'。
我的灵感来自docs。
class Author extends ManagedObject<_Author> implements _Author {
@Serialize(input: false, output: true)
int get numBooks => books.length;
}
class _Author {
@primaryKey
int id;
@Column(unique: true)
String name;
ManagedSet<Book> books;
}
class Book extends ManagedObject<_Book> implements _Book {}
class _Book {
@primaryKey
int id;
@Relate(#books)
Author author;
}
我正在使用渡槽 3.2.1。