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

Support for meta object doesn't seem to work #36

Open
cedv opened this issue Nov 1, 2016 · 3 comments
Open

Support for meta object doesn't seem to work #36

cedv opened this issue Nov 1, 2016 · 3 comments

Comments

@cedv
Copy link

cedv commented Nov 1, 2016

Support for meta object doesn't seem to work.

I tried with both store.sync and store.syncWithMeta, and either way, I can't see the meta information in the datastore when I pull the record using store.find. The rest of the data is fine; I can see the attributes, relationships and links.

This is how I use the datastore (within some AngularJS code):

var store = JsonApiDataStore.store;
store.sync(payload);
$scope.client = store.find('clients', 700);

And this is my JSON payload:

{
  "data": {
    "id": "700",
    "type": "clients",
    "links": {
      "self": "http://localhost:3000/clients/700"
    },
    "attributes": {
      "name": "Dummy Client"
    },
    "relationships": {
      "clientType": {
        "links": {
          "self": "http://localhost:3000/clients/700/relationships/client-type",
          "related": "http://localhost:3000/clients/700/client-type"
        },
        "data": {
          "type": "clientTypes",
          "id": "INTERNAL"
        }
      }
    },
    "meta": {
      "created": {
        "at": "1372275070780",
        "by": {
          "userName": "sys",
          "name": "System",
          "emailAddress": "system@example.com"
        }
      }
    }
  }
}
@amwmedia
Copy link
Contributor

amwmedia commented Nov 1, 2016

I believe you need to use syncWithMeta

@italopaiva
Copy link

@amwmedia, I believe he means that he couldn't retrieve the meta information in the store object after doing store.syncWithMeta(payload). I'm kinda having the same problem to retrieve the meta object after syncing it in the store. Is there something like store.metadata() to retrieve this information from the store?

@beauby
Copy link
Owner

beauby commented Jul 13, 2017

@cedv @italopaiva As you can see here, the syncWithMeta method will return an object containing the meta data. So you should do:

var res = store.syncWithMeta(payload);
console.log(res.meta);

I agree the README is not clear on that point. Would any of you guys mind opening a docs PR?

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

No branches or pull requests

4 participants