Skip to content

Allow OneToMany style lookups with via DocumentReference. #3802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

christophstrobl
Copy link
Member

This PR adds support for relational style One-To-Many references using a combination of @ReadonlyProperty and @DocumentReference.
It allows to link types without explicitly storing the linking values within the document itself.

@Document
class Book {

  @Id
  ObjectId id;
  String title;
  List<String> author;

  ObjectId publisherId;
}

@Document
class Publisher {

  @Id
  ObjectId id;
  String acronym;
  String name;

  @ReadOnlyProperty
  @DocumentReference(lookup="{'publisherId':?#{#self._id} }")
  List<Book> books;
}

Book

{
  "_id" : "9a48e32",
  "title" : "The Warded Man",
  "author" : ["Peter V. Brett"],
  "publisherId" : "8cfb002"
}

Publisher

{
  "_id" : "8cfb002",
  "acronym" : "DR",
  "name" : "Del Rey"
}

Closes: #3798

This commit adds support for relational style One-To-Many references using a combination of ReadonlyProperty and @DocumentReference.
It allows to link types without explicitly storing the linking values within the document itself.

@document
class Publisher {

  @id
  ObjectId id;
  // ...

  @ReadOnlyProperty
  @DocumentReference(lookup="{'publisherId':?#{#self._id} }")
  List<Book> books;
}
@mp911de mp911de self-assigned this Sep 8, 2021
@mp911de mp911de added this to the 3.3 M3 (2021.1.0) milestone Sep 8, 2021
mp911de pushed a commit that referenced this pull request Sep 8, 2021
This commit adds support for relational style One-To-Many references using a combination of ReadonlyProperty and @DocumentReference.
It allows to link types without explicitly storing the linking values within the document itself.

@document
class Publisher {

  @id
  ObjectId id;
  // ...

  @ReadOnlyProperty
  @DocumentReference(lookup="{'publisherId':?#{#self._id} }")
  List<Book> books;
}

Closes: #3798
Original pull request: #3802.
mp911de added a commit that referenced this pull request Sep 8, 2021
Tweak reference documentation wording. Extract self/target source dereferencing into utility methods.

See: #3798
Original pull request: #3802.
@mp911de
Copy link
Member

mp911de commented Sep 8, 2021

That's merged and polished now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance @DocumentReference to allow one-to-many style lookups
2 participants