From b6e67241ea57a01d7f75b5151abef6afd77e99ea Mon Sep 17 00:00:00 2001 From: Jonathan Stassen Date: Fri, 26 Jun 2015 12:24:01 -0500 Subject: [PATCH] Support for matching models on other uniqueAttributes. See #60 --- supermodel.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/supermodel.js b/supermodel.js index ec8ee18..6b5fadf 100644 --- a/supermodel.js +++ b/supermodel.js @@ -483,6 +483,17 @@ return model; } + // If found by one of our model's other uniqueAttributes, return it. See Issue #60 + if (this.prototype.uniqueAttributes) { + _.each(this.prototype.uniqueAttributes, function(value) { + if (_.has(attrs, value)){ + model = all.find(function(item) { return item.get( value ) == attrs[value]; }); + if (model) return model; + } + }); + if (model) return model; + } + // Throw if a model already exists with the same id in a superclass. var parent = this; while (parent = parent.parent) {