schultek / stormberry

Access your postgres database effortlessly from dart code.
https://pub.dev/packages/stormberry
MIT License
66 stars 16 forks source link

The method 'ThisViewQueryable' isn't defined for the type 'ThatViewQueryable' #62

Closed easazade closed 1 year ago

easazade commented 1 year ago

Got two models, user and post each with 2 different views complete and reduced. very similar to the example There are syntax errors in generated code

The method 'PostViewQueryable' isn't defined for the type 'UserViewQueryable'. The name 'PostView' isn't a type, so it can't be used as a type argument

here are the models

@Model(views: [#CompletePost, #ReducedPost])
abstract class Post {
  @PrimaryKey()
  @AutoIncrement()
  int get id;

  String get title;

  String get content;

  @BindTo(#posts)
  @ViewedIn(#CompletePost, as: #ReducedUser)
  @HiddenIn(#ReducedPost)
  User get author;

  User get editor;
}

@Model(views: [#CompleteUser, #ReducedUser])
abstract class User {
  @PrimaryKey()
  @AutoIncrement()
  int get id;

  String get name;

  String get bio;

  @BindTo(#author)
  @ViewedIn(#CompleteUser, as: #ReducedPost)
  @HiddenIn(#ReducedUser)
  List<Post> get posts;
}

you can find generated schema file here. there are 3 lines with errors at the end I commented them

also you can find the complete code here you need to git checkout this commit though: db949bd

hint: errors will be different when I change the order of the models in the file

schultek commented 1 year ago

Thanks for reporting.

I not to add an error message describing this, but to fix this you also need to annotate the editor user with either HiddenIn or ViewedIn for both user views.

easazade commented 1 year ago

added those annotations and now it works

@ViewedIn(#CompletePost, as: #ReducedUser)
@HiddenIn(#ReducedPost)
User? get editor;