objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

_QueryStringVectorProperty.notContains #260

Closed frogman1189 closed 2 months ago

frogman1189 commented 2 years ago

I have an object that looks like

@Entity()
class Post {
  int id;
  List<String>? readByIds
  // other properties

  queryObject({this.id = 0, this.readByIds});
}

And I would like to be able to retrieve Posts I have not read. It would be useful if the generated metadata had the .notContains function for this kind of situation. i.e box.query(Post_.notContains(userId))

In my situation I know all the ids of who could read it, and so have added an extra property that is the inverse readByIds:

@Entity()
class Post {
  int id;
  List<String>? readByIds;
  List<String>? notReadByIds;
  // other properties

  queryObject({this.id = 0, this.readByIds, this.notReadByIds});
}

but the duplication makes this undesirable

vaind commented 2 years ago

Would need to be implemented in the core. I'm raising a feature request there.

vaind commented 2 years ago

BTW, this looks like a good candidate for a separate "table" with the list of which items have been read by which user (assuming that's what you mean by readByIds), e.g.

@Entity()
class Post {
  int id;
  ...
}

@Entity()
class PostReads {
  int id;
  final post = ToOne<Post>();
  final user = ToOne<User>();
}
greenrobot-team commented 2 months ago

As this is kind of asking for the notOneOf condition and to track interest in one place, closing this as a duplicate of #591.