Skip to content

feat(populate): Support multiple 1:N relationships on key #140

Open
@Domiii

Description

@Domiii

Currently, for each entry in the populates array one object is grabbed from a single path, which is then used to replace it's "lookup key" in the original object. However, I want to present another common usage scenario - multiple one-to-many relationships on a single (foreign) key:

Scenario example

Data

  • /submission/$(submissionId)
  • /feedback/$(feedbackId) where each child has submissionId
  • /notifications/$(notificationId) where each child has submissionId

There can be multiple feedback and multiple notifications entries for each submission.

Grabbing all feedback and notifications with each submission

From what I understand from the v1.5 updates, there is (will be) a way to provide a function for populates that has key and obj parameters that returns the configuration array at query time. While that gives us the submissionId, I don't think it allows us to create a full-on query?

I am thinking of something along the lines of:

{
  path: 'submissions',
  populates: (submissionId, submission) => [
    {
      root: 'feedback',
      targetKey: 'feedback',   // will store the feedback data at the `submission`'s `feedback` property
      queryParams: [ `orderByChild=submissionId`, `equalTo=${submissionId}`]
    },
    {
      root: 'notifications',
      targetKey: 'notifications',   // will store the feedback data at the `submission`'s `notifications` property
      queryParams: [ `orderByChild=submissionId`, `equalTo=${submissionId}`]
    }
  ]
}

NOTE: In this case, there is no child, and instead we get a queryParams because we want to get all matching children in the given root path.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions