Skip to content

Add checks for null collections #202

michaelbrooks opened this Issue Sep 30, 2012 · 6 comments

5 participants


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) {


// 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.


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


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 commented Oct 1, 2012

This thread was really helpful!

wprl commented Oct 1, 2012

Added pull request that adds the || []s

jdalton commented Oct 4, 2012

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.


Has been fixed, thanks all!

@PaulUithol PaulUithol closed this Dec 14, 2012
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.