jsonapi-datastore icon indicating copy to clipboard operation
jsonapi-datastore copied to clipboard

Add included objects to serialized JSON

Open mklocek opened this issue 9 years ago • 2 comments

In one of my apps using jsonapi-datastore I needed a way to include to result of serialize method an array of complete relationship objects, just like in jsonapi specification. For my purposes, I created this: mklocek/jsonapi-datastore@a955efec9ecaba87a0dde0598232d1822022df3a. Including is optional here and looks like that:

var projectAttributes = {
    attributes: ['title'],
    relationships: ['clients', 'managers'],
    included: {
        clients: {
            attributes: ['name']
        },
        managers: {
            attributes: ['name']
        }
    }
};

project.serialize(projectAttributes);
=> # jsonapi json containing 'included' array

Have you thought about such feature?

mklocek avatar Dec 30 '15 14:12 mklocek

Hi @mklocek. jsonapi-datastore was intended as a client-side library. Hence, creating payloads with an included property was not in the requirements, as (AFAIK) only a server would have to generate those. Would you mind elaborating on your use-case?

beauby avatar Dec 30 '15 15:12 beauby

Hi @beauby! I needed a way to create nested_form-like api requests. That's not the way things are made in jsonapi specification, just my use-case, so I didn't make PR. Just wondering if it could be a good feature for you.

mklocek avatar Dec 31 '15 08:12 mklocek