Created
February 8, 2014 20:51
-
-
Save ryanflorence/8890115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Ember = require('ember'); | |
Ember.Route.reopen({ | |
model: function(params, transition) { | |
var match, name, sawParams, value; | |
for (var prop in params) { | |
if (prop === 'queryParams') { continue; } | |
if (match = prop.match(/^(.*)_id$/)) { | |
name = match[1]; | |
value = params[prop]; | |
} | |
sawParams = true; | |
} | |
if (!name && sawParams) { | |
return Ember.copy(params); | |
} else if (!name) { | |
if (transition.resolveIndex !== transition.state.handlerInfos.length-1) { return; } | |
var parentModel = transition.state.handlerInfos[transition.resolveIndex-1].context; | |
return parentModel; | |
} | |
return this.findModel(name, value); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment