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

Record $decode expected an object #372

Open
laszl0 opened this issue Mar 5, 2016 · 3 comments
Open

Record $decode expected an object #372

laszl0 opened this issue Mar 5, 2016 · 3 comments

Comments

@laszl0
Copy link

laszl0 commented Mar 5, 2016

Hello, this project is fantastic, thank you for the creators, they saved lots of hours that i can use for other things. Thanks.

Today i started using it and after spending half a day with it, my first issue arrived.
I try to use the find to get the data for a resource

$scope.post = Post.$find($scope.postId);

and i get the error:

Record $decode expected an object

I made a code snipped to replicate the problem. Here it is http://codepen.io/anon/pen/LNpMXK

Forgot to say that my response for the resource from the api is a raw resource object.

{ "userId": 1, "id": 1, "title": "sunt aut ", "body": "quia et " }

My findings.

I traced the issue to this method:

return restmod.mixin(function() {
  this.define('Model.unpack', function(_resource, _raw) {
      var name = null,
          links = this.getProperty('jsonLinks', 'included'),
          meta = this.getProperty('jsonMeta', 'meta');
        ...
        ...
      return _raw[name]; // here it returns undefined
    });

and on the return line, the name has a value that is not present as property on the _raw object.
I have used the following:

jsonRootSingle: '.' // but of course this is sily

Hack to get it working.

restmodProvider.rebase({
      $config: {        
        jsonRootSingle: '_single', // hack
      },
      $hooks: {
        'after-request' : function (_res) {
          // this hack is needed because $find is giving the error...
          // ...Record $decode expected an object
          // comment out the line below to get the error
          _res.data = Array.isArray(_res.data) ? _res.data : {_single: _res.data};
        }
      }
    });
@2624789
Copy link

2624789 commented Aug 27, 2016

had the same problem with $save() and this hack works, but breaks $search().

any suggestion?

@2624789
Copy link

2624789 commented Aug 27, 2016

Found my problem was related with the api response, modified it and everything works ok.

It seems this error is related to the api, not the restmod angular.

@laszl0
Copy link
Author

laszl0 commented Aug 27, 2016

Great to hear that you solved your problem :).
As i said above, my problem was with "raw resource object".

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

No branches or pull requests

2 participants