Ignore parentResource when restangularizing object with option to include
See original GitHub issueConsider:
// GET /accounts/5/mails
var mails = Restangular.one('accounts', 5).getList('mails');
// Logs: /accounts/5/mails/1
console.log(mails[0].getRestangularUrl());
// PUT: /accounts/5/mails/1
mails[0].body = 'Changed Body of Mail';
mails[0].put();
A lot of RESTful best practices (http://info.apigee.com/Portals/62317/docs/web api.pdf) suggest “Remember that once you have the primary key for one level, you usually don’t need to include the levels above because you’ve already got your specific object. In other words, you shouldn’t need too many cases where a URL is deeper than /resource/identifier/resource
”.
For the above example code and taking this best practice to heart it would be better for the getRestangularUrl and PUT/DELETE etc operations to work as follows:
// GET /accounts/5/mails
var mails = Restangular.one('accounts', 5).getList('mails');
// Logs: /mails/1
console.log(mails[0].getRestangularUrl());
// PUT: /mails/1
mails[0].body = 'Changed Body of Mail';
mails[0].put();
So that the children of the restangularCollection point to their base object url unless we optionally specify to include it’s parent in the URL eg: mails[0].withParents().getRestangularUrl()
, mails[0].withParents().put()
perhaps?
Issue Analytics
- State:
- Created 10 years ago
- Comments:17 (9 by maintainers)
Top GitHub Comments
@mgonto Ah, there is one bug I found with it.
I’ve been thinking on adding URL Building to this feature, but all I’ve comed up with is kind of hacky, so I think that for now, I won’t leave URL Building in. IF you want to build a URL, you can set those resources as “parentful” and that’s it 😃