Skip to content

Commit

Permalink
Revert "Merge pull request #396 from saponifi3d/josh-revert-collections"
Browse files Browse the repository at this point in the history
This reverts commit 0ebca7c, reversing
changes made to ef52957.
  • Loading branch information
Santiago Archila committed Sep 11, 2014
1 parent 0ebca7c commit aa278bb
Show file tree
Hide file tree
Showing 2 changed files with 364 additions and 106 deletions.
21 changes: 17 additions & 4 deletions shared/syncer.js
Expand Up @@ -32,7 +32,8 @@ var syncer = module.exports;
function clientSync(method, model, options) {
var error;
options = _.clone(options);
options.url = this.getUrl(options.url, true);
options.data = _.clone(options.data);
options.url = this.getUrl(options.url, true, options.data);
error = options.error;
if (error) {
options.error = function(xhr) {
Expand All @@ -55,18 +56,25 @@ function clientSync(method, model, options) {
}

function serverSync(method, model, options) {
var api, urlParts, verb, req;
var api, urlParts, verb, req, queryStr;

options = _.clone(options);
options.url = this.getUrl(options.url, false);
options.data = _.clone(options.data);
options.url = this.getUrl(options.url, false, options.data);
verb = methodMap[method];
urlParts = options.url.split('?');
req = this.app.req;
queryStr = urlParts[1] || '';
if (!_.isEmpty(options.data)) queryStr += '&' + qs.stringify(options.data);
/**
* if queryStr is initially an empty string, leading '&' will still get parsed correctly by qs.parse below.
* e.g. qs.parse('&baz=quux') => { baz: quux }
*/

api = {
method: verb,
path: urlParts[0],
query: qs.parse(urlParts[1]) || {},
query: qs.parse(queryStr),
headers: options.headers || {},
api: _.result(this, 'api'),
body: {}
Expand Down Expand Up @@ -229,5 +237,10 @@ syncer.interpolateParams = function interpolateParams(model, url, params) {
delete params[property];
});
}
/**
* Separate deletion of idAttribute from params hash necessary if using urlRoot in the model
* so we don't get urls like: /v1/threads/1234?id=1234
*/
delete params[model.idAttribute]
return url;
};

0 comments on commit aa278bb

Please sign in to comment.