This looks like typical mysql/db work actually.
You may want to structure this differently actually:
this.model = MyModel.find({id:id});
try {
this.doSomething();
} catch (e) {
if (e instanceof SomeSpecificException) {
var fetchPromise = this.model.fetch();
fetchPromise.done(
this.doSomething.bind(this)
);
}
}
What's happening here?
Try/Catch is a great way to notice something is not found or not existent. If you catch an error then you can fetch. Fetch should return a future/promise (if it doesn't write a shim that fixes up its prototype). When the promise resolves (comes back done) it'll call doSomething whose scope will be bound to this. That let's you remove self.
How to shim?
It'd be something like:
var Deferred = require('simply-deferred');
Backbone.Model.prototype.fetch = function(options) {
var dfd = Deferred();
Backbone.Model.prototype.fetch.call(
this,
_.extend({ success: dfd.resolve.bind(this) }, options)
);
return dfd.promise;
}
The only part I'm not sure about is which function to use: Backbone.Model.prototype.fetch might point to the original Backbone fetch. You essentially want to call the Backbone-Relational fetch method pass in your options and scope. Then have the success option to resolve your promise.
Why isn't this built in? Well someone in node land decided promises weren't the default way to go thus leaving you in call back hell.