1

in my model a Author has many Books. Is it possible to get the amount of books per author a transient property?

This is what I tried but it says:

NoSuchMethodError: The getter 'length' was called on null.

My inspiration came from the 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;
}

I am using Aqueduct 3.2.1.

1 Answers1

0

I think it isn't possible cause book is a related field.

You can use .join() in controller in order to get all the books.

David
  • 923
  • 8
  • 19