Comment and code don't make sense together in `RelationalModel.setup()` #475

Closed
dminkovsky opened this Issue Jun 19, 2014 · 1 comment

Comments

Projects
None yet
2 participants

Dear Paul,

Please take a look at

setup: function( superModel ) {
// We don't want to share a relations array with a parent, as this will cause problems with reverse
// relations. Since `relations` may also be a property or function, only use slice if we have an array.
this.prototype.relations = ( this.prototype.relations || [] ).slice( 0 );
.

The comment and code combination doesn't make sense to me:

// We don't want to share a relations array with a parent, as this will cause problems with reverse
// relations. Since `relations` may also be a property or function, only use slice if we have an array.
this.prototype.relations = ( this.prototype.relations || [] ).slice( 0 );

If this.prototype.relations is a function, this doesn't work.

I also don't understand the part about sharing a relations array with a parent. In this execution scope, aren't the parent's relations this.__super__.relations?

Owner

PaulUithol commented Aug 6, 2014

This is an old comment. Removing that part, thanks.

Reusing the relations array on child models will cause a reverse relations to (attempt to) initialize for each child class; it'll fail for any but the first to try it. Same reason basically why Backbone doesn't inherit events either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment