objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

_QueryStringVectorProperty.notContains

Open frogman1189 opened this issue 4 years ago • 2 comments

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

frogman1189 avatar Jun 02 '21 05:06 frogman1189

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

vaind avatar Jun 23 '21 07:06 vaind

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>();
}

vaind avatar Jun 23 '21 07:06 vaind

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

greenrobot-team avatar Feb 28 '24 07:02 greenrobot-team