Skip to content
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

Advanced populating? #42

Closed
DeividasK opened this issue Jan 26, 2017 · 8 comments
Closed

Advanced populating? #42

DeividasK opened this issue Jan 26, 2017 · 8 comments
Assignees
Labels

Comments

@DeividasK
Copy link

A question regarding populate with the following data structure:

actions: {
  actionId: {
    goalId: 'goalId1',
    done: false
  },
  actionId2: {
    goalId: 'goalId1',
    done: false
  }
}
goals: {
  goalId1: {
    text: 'Goal title'
  }
}

How would I go about populating goals with actions?

Conditions:

  • User has many goals
  • Goals have many actions
  • I want to display several goals with their actions
@prescottprue
Copy link
Owner

prescottprue commented Jan 26, 2017

First, I would suggest taking the pattern of storing data how it will be viewed (i.e. storing a list of actions within goals). This is actually follows Firebase's Docs on "creating structured data that scales":

actions: {
  actionId: {
    goalId: 'goalId1',
    done: false
  },
  actionId2: {
    goalId: 'goalId1',
    done: false
  }
}
goals: {
  goalId1: {
    text: 'Goal title',
    actions: {
      actionId: true,
      actionId2: true
    }
  }
}

Then when calling, you can list goals with populated actions like so:

const populates = [{ child: 'actions', root: 'actions' }]
@firebaseConnect(() => ([
  { path: 'goals', populates }
]))

or actions with the associated goal populated like this:

const populates = [{ child: 'goalId', root: 'goals' }]
@firebaseConnect(() => ([
  { path: 'actions', populates }
]))

@DeividasK
Copy link
Author

Thanks for the help!

@DeividasK
Copy link
Author

I am working on implementing the above, but it doesn't seem to work. I have created the recommended structure.

My code:

const populates = [{ child: 'actions', root: 'actions' }]
@firebaseConnect(() => ([ { path: 'goals', populates } ]))
@connect(({ firebase }) => ({
  users: populatedDataToJS(firebase, 'goals', populates),
}))

The result is an unmodified object of action ids, i.e.

actions: {
  actionId: true,
  actionId2: true
}

Any ideas?

Package version: 1.2.2

@DeividasK DeividasK reopened this Jan 30, 2017
@prescottprue
Copy link
Owner

That seems like it should be working correctly. I will attempt to replicate using the simple example and get back to you.

@prescottprue
Copy link
Owner

prescottprue commented Feb 1, 2017

Right you are!

It seems that there is an issue gathering the data when populating a parameter that is a Firebase lists (key: true) within each item in a list.

I've started a branch for v1.2.3 where I have fixed this issue and added tests that will make sure that this doesn't break in the future. Trying to release it pretty soon (hopefully tomorrow).

@prescottprue prescottprue self-assigned this Feb 1, 2017
This was referenced Feb 1, 2017
prescottprue added a commit that referenced this issue Feb 1, 2017
* Population of list with items containing a child param that is Firebase list (`key: true`) using `populatedDataToJS` (#42)
* `populatedDataToJS` supports childParam option (#48)
* `populatedDataToJS` returns null for empty lists instead of `undefined` (#50)
* Unit tests added to cover all cases within `populatedDataToJS`
@prescottprue
Copy link
Owner

v1.2.3 should hopefully solve this issue, but I will leave it open until that is confirmed.

@DeividasK
Copy link
Author

Great news! I can confirm that this now works as expected. Thanks a lot!

@prescottprue
Copy link
Owner

Glad to hear.

There is a unit test for this pattern now too, so it shouldn't be an issue moving forward.

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

No branches or pull requests

2 participants