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

Deep creating relations with pass option doesn't work

Open Tyler-Zhang opened this issue 5 years ago • 2 comments

I can't seem to get this example

const postProps = {
  title: 'Relations',
  comments: [
    {
      content: 'Awesome!'
    },
    {
      content: 'So cool!'
    }
  ]
};

store.create('post', postProps, { pass: ['comments'] })
  .then((post) => {
  	// done
  
		post.id === post.comments[0].post_id; // true!
  });

at https://www.js-data.io/docs/relations#section-deep-creating-relations to work.

Although the objects serialize properly, the base adapter's withoutSerialization call on create, createMany, update, etc... filters out the relations because it expects the whitelisted relations to be specified in opts.with instead of opts.pass.

https://next.plnkr.co/edit/IXtJWp3gDy3fgqfY?preview

Tyler-Zhang avatar May 09 '19 00:05 Tyler-Zhang

Just copying opts.pass to opts.with works for me:

https://github.com/Tyler-Zhang/js-data-http/tree/fix-deep-creating-relations-with-pass-opts

Tyler-Zhang avatar May 09 '19 00:05 Tyler-Zhang

Copying opts.pass content to opts.with allows to bypass the filtering but it triggers a cascading create.

Septaris avatar Jun 13 '19 13:06 Septaris