From aedc09b2b3dc997a914914d1147f7033765a697b Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Fri, 19 Feb 2016 11:52:49 -0800 Subject: [PATCH] fix(metadata): Correctly call modelify for latest models when setting metadata --- src/flux/stores/metadata-store.es6 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/flux/stores/metadata-store.es6 b/src/flux/stores/metadata-store.es6 index 99dea14e0..caef3563a 100644 --- a/src/flux/stores/metadata-store.es6 +++ b/src/flux/stores/metadata-store.es6 @@ -13,12 +13,16 @@ class MetadataStore extends NylasStore { _setMetadata(modelOrModels, pluginId, metadataValue) { const models = (modelOrModels instanceof Array) ? modelOrModels : [modelOrModels]; + const modelClass = models[0].constructor + if (!models.every(m => m.constructor === modelClass)) { + throw new Error('Actions.setMetadata - All models provided must be of the same type') + } DatabaseStore.inTransaction((t)=> { // Get the latest version of the models from the datbaase before applying // metadata in case other plugins also saved metadata, and we don't want // to overwrite it return ( - t.modelify(_.pluck(models, 'clientId')) + t.modelify(modelClass, _.pluck(models, 'clientId')) .then((latestModels)=> { const updatedModels = latestModels.map(m => m.applyPluginMetadata(pluginId, metadataValue)); return (