Skip to content

Commit

Permalink
Merge pull request jashkenas#2426 from gsamokovarov/no-url-no-urlroot
Browse files Browse the repository at this point in the history
Don't accept urlRoot from Model and url from Collection
  • Loading branch information
jashkenas committed Mar 26, 2013
2 parents 820182b + 5b8f794 commit dd85833
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
6 changes: 1 addition & 5 deletions backbone.js
Expand Up @@ -248,7 +248,7 @@
options || (options = {});
this.cid = _.uniqueId('c');
this.attributes = {};
_.extend(this, _.pick(options, modelOptions));
if (options.collection) this.collection = options.collection;
if (options.parse) attrs = this.parse(attrs, options) || {};
if (defaults = _.result(this, 'defaults')) {
attrs = _.defaults({}, attrs, defaults);
Expand All @@ -258,9 +258,6 @@
this.initialize.apply(this, arguments);
};

// A list of options to be attached directly to the model, if provided.
var modelOptions = ['urlRoot', 'collection'];

// Attach all inheritable methods to the Model prototype.
_.extend(Model.prototype, Events, {

Expand Down Expand Up @@ -596,7 +593,6 @@
// its models in sort order, as they're added and removed.
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
if (options.url) this.url = options.url;
if (options.model) this.model = options.model;
if (options.comparator !== void 0) this.comparator = options.comparator;
this._reset();
Expand Down
9 changes: 2 additions & 7 deletions index.html
Expand Up @@ -987,11 +987,6 @@ <h2 id="Model">Backbone.Model</h2>
otherwise added automatically when you first add a model to a collection.
</p>

<p>
<tt>{urlRoot: "..."}</tt> option may be passed when creating a new model
that needs to have a custom one-off URL endpoint.
</p>

<p>
If <tt>{parse: true}</tt> is passed as an <b>option</b>, the <b>attributes</b>
will first be converted by <a href="#Model-parse">parse</a> before being
Expand Down Expand Up @@ -1609,8 +1604,8 @@ <h2 id="Collection">Backbone.Collection</h2>
may be included as an option. Passing <tt>false</tt> as the
comparator option will prevent sorting. If you define an
<b>initialize</b> function, it will be invoked when the collection is
created. There are several options that, if provided, are attached to the
collection directly: <tt>url</tt>, <tt>model</tt> and <tt>comparator</tt>.
created. There are a couple of options that, if provided, are attached to
the collection directly: <tt>model</tt> and <tt>comparator</tt>.
</p>

<pre>
Expand Down
5 changes: 1 addition & 4 deletions test/collection.js
Expand Up @@ -1081,18 +1081,15 @@ $(document).ready(function() {
collection.add(collection.models, {merge: true}); // don't sort
});

test("Attach options to collection.", 3, function() {
var url = '/somewhere';
test("Attach options to collection.", 2, function() {
var model = new Backbone.Model;
var comparator = function(){};

var collection = new Backbone.Collection([], {
url: url,
model: model,
comparator: comparator
});

strictEqual(collection.url, url);
ok(collection.model === model);
ok(collection.comparator === comparator);
});
Expand Down
5 changes: 0 additions & 5 deletions test/model.js
Expand Up @@ -111,11 +111,6 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2');
});

test('urlRoot is directly attached if passed in the options', 1, function () {
var model = new Backbone.Model({a: 2}, {urlRoot: '/test'});
equal(model.urlRoot, '/test');
});

test("underscore methods", 5, function() {
var model = new Backbone.Model({ 'foo': 'a', 'bar': 'b', 'baz': 'c' });
var model2 = model.clone();
Expand Down

0 comments on commit dd85833

Please sign in to comment.