Index: app/models/models.js |
=== modified file 'app/models/models.js' |
--- app/models/models.js 2013-06-27 15:26:46 +0000 |
+++ app/models/models.js 2013-07-05 16:23:50 +0000 |
@@ -300,11 +300,26 @@ |
process_delta: function(action, data, db) { |
var instance = _process_delta(this, action, data, {relation_errors: {}}); |
- if (!instance || !db) {return;} |
+ if (!db) { |
+ return; |
+ } |
// Apply this action for this instance to all service models as well. |
// In the future we can transition from using db.units to always |
- // looking at db.services[serviceId].units |
- var service = db.services.getById(instance.service); |
+ // looking at db.services[serviceId].units. Note that, in the case of |
+ // `action === 'remove'`, instance will be null, so we retrieve the |
+ // service name from `data`, which is the removed unit's name. |
+ var service; |
+ if (!instance) { |
+ if (typeof data === 'string') { |
+ service = db.services.getById(data.split('/')[0]); |
+ } else if (data.service) { |
+ service = db.services.getById(data.service); |
+ } else { |
+ return; |
+ } |
+ } else { |
+ service = db.services.getById(instance.service); |
+ } |
if (!service) { return; } |
// Get the unit list for this service. (lazy) |
var unitList = service.get('units'); |