Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add checks for null collections #202

Closed
michaelbrooks opened this Issue · 6 comments

5 participants

@michaelbrooks

Apparently, underscore.js no longer checks if collections are null. The topic is discussed in this issue: jashkenas/underscore#744

In my application, this is causing an error on line 924 where _.any is used to find an entity in this.keyContents, but this.keyContents is undefined.

Specifically, once _.any is called, the check if obj.some === nativeSome fails because obj is undefined.

The fix for this could be something like:

// Check if this new model was specified in 'this.keyContents'
var item = _.any(this.keyContents, function(item) {

to

// Check if this new model was specified in 'this.keyContents'
var item = _.any(this.keyContents || [], function(item) {

I'm guessing there are other places in backbone-relational that need to be updated as well, though. Someone else should probably take a deeper look at this than I can right now.

@philfreo
Collaborator

yep... backbone-relational is broken on underscore 1.4.0 :(

also _.each( models , function( related ) { in getReverseRelations throws an error now when models is null

@philfreo
Collaborator

though for what it's worth, I think those 2 changes are the only places that needed to be changed (at least with obvious errors for me)

@wprl

This thread was really helpful!

@wprl

Added pull request that adds the || []s

@jdalton

Just a heads up, Lo-Dash v0.8.1 won't error when falsey values are passed to collection methods. So you can use it w/o having to modify your project's code.

@PaulUithol
Owner

Has been fixed, thanks all!

@PaulUithol PaulUithol closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.