documentcloud/backbone — Issue #714: Collection binding is too late in Model constructor
Author: perfectworks
Created: 2011-11-03 05:17:37+00:00
State: open

Backbone.js is great, it's so useful in single page app!

And I found a issue: I can't use this.collection in Model.set method.

```javascript
var SomeModel = Model.extend({
// ...
set: function(attributes, options) {
var duplicate = this.collection.get(attributes.id); // Error, this.collection is undefined
}
// ...
});
```

In code of Model.constructor, the collection binding is after Model.set:

```javascript
Backbone.Model = function(attributes, options) {
// ...
this.set(attributes, {silent : true});
// ...
if (options && options.collection) this.collection = options.collection;
// ...
};

```

So, I think the binding of collection should move above of this.set;