-
Notifications
You must be signed in to change notification settings - Fork 87
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
unpack function unable to determine name on nested resources #224
Comments
Hi @garethhudson07, when using nested resources you should explicitly provide a name for the resource, like this: app.factory('Item', function(restmod) {
return restmod.model().mix({
$config: { name: 'item' }
});
}); That way the unpacker knows where to look for data in the response. |
Hi @iobaixas, thanks for your reply. I have updated my code but am still having problems and am getting the same error as before Collection $decode expected array It seems that the getProperty('plural') method is returning undefined despite the fact that getProperty('name') now returns "item"; return restmod.mixin(function() {
this.define('Model.unpack', function(_resource, _raw) {
var name = null,
links = this.getProperty('jsonLinks', 'linked'),
meta = this.getProperty('jsonMeta', 'meta');
if(_resource.$isCollection) {
name = this.getProperty('jsonRootMany') || this.getProperty('jsonRoot') || this.getProperty('plural');
console.log(this.getProperty('name')); //returns item
console.log(this.getProperty('plural')); //returns undefined
} else {
// TODO: use plural for single resource option.
name = this.getProperty('jsonRootSingle') || this.getProperty('jsonRoot') || this.getProperty('name');
}
if(meta) {
_resource.$metadata = {};
processFeature(_raw, name, meta, links, function(_key, _value) {
_resource.$metadata[_key] = _value;
});
}
if(links) {
processFeature(_raw, name, links, meta, function(_key, _value) {
// TODO: check that cache is an array.
packerCache.feed(_key, _value);
});
}
return _raw[name];
});
}); I would really appreciate any guidance on this. Thanks :) |
I was wrong 😞, the plural property does not get generated automatically if you change the name property, you will have to set the plural name too in the app.factory('Item', function(restmod) {
return restmod.model().mix({
$config: {
name: 'item',
plural: 'items'
}
});
}); I'll mark this as a bug, the fix is not easy though... |
Hi @iobaixas, that's got it working. Thanks for your help :) |
Hi guys
Just started using the library and really liking it so far.
I am having an issue with nested resources and getting the following error:
Collection $decode expected array
My json responses are as follows:
I have left the url blank in the nested resource as per my understanding from the docs. However it seems that the unpack function is unable to determine the name.
when I added a console.log(name) to the unpack function it ouput undefined
Is this a bug? If not any guidance on what I am doing wrong would be greatly appreciated :)
The text was updated successfully, but these errors were encountered: