js-data-firebase icon indicating copy to clipboard operation
js-data-firebase copied to clipboard

Parent relationship not working as in HTTP Adapter

Open JoaoMosmann opened this issue 8 years ago • 3 comments

I'm not sure if it's on purpose. But I thought that by defining a resource as belonging to another resource using the property parent: true It would behave as in the HTTP Adapter which mounts the endpoint relative to its parent.

If this is a planned feature that was forgotten, I can do a PR. If not, why ?

e.g:

var Comment = store.defineResource({
  name: 'comment',
  relations: {
    belongsTo: {
      post: {
        parent: true,
        localKey: 'postId',
        localField: 'post'
      }
    }
  }
});

Comment.find(5, { params: { postId: 4 } }); // GET /post/4/comment/5

JoaoMosmann avatar Apr 05 '16 01:04 JoaoMosmann

I only ever imagined parent: true to be something the http adapter uses.

jmdobry avatar Apr 06 '16 04:04 jmdobry

I believe it would be a good feature for this adapter. Because the Firebase endpoints follows the REST pattern as the urls used in the HttpAdapter.

However, Firebase doesn't recommend to do a nested data structure. But I think it should be up to the developer.

JoaoMosmann avatar Apr 06 '16 12:04 JoaoMosmann

Firebase doesn't recommend to do a nested data structure

I agree with that, as your Firebase database is just a large JSON tree, nested data requires that the client download inordinate amounts of data.

But I think it should be up to the developer.

Right. Would you be interested in adding support for this to js-data-firebase? I imagine you already have some code to handle this in your app.

jmdobry avatar Sep 20 '16 14:09 jmdobry