From bea9c0b07a5f844a6a1a0e0a3aa6641bf1343466 Mon Sep 17 00:00:00 2001 From: Diogo Resende Date: Tue, 30 Jul 2013 18:57:44 +0100 Subject: [PATCH] Allows user to pass an object to extendsTo.setAccessor instead of an instance (detected via #250) --- lib/Associations/Extend.js | 4 ++++ lib/Instance.js | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/Associations/Extend.js b/lib/Associations/Extend.js index 36357f0f..e02f7fdc 100644 --- a/lib/Associations/Extend.js +++ b/lib/Associations/Extend.js @@ -108,6 +108,10 @@ function extendInstance(Model, Instance, Driver, association, opts) { var fields = Object.keys(association.field); + if (!Extension.isInstance) { + Extension = new association.model(Extension); + } + for (var i = 0; i < Model.id.length; i++) { Extension[fields[i]] = Instance[Model.id[i]]; } diff --git a/lib/Instance.js b/lib/Instance.js index d7557b4f..c9714221 100755 --- a/lib/Instance.js +++ b/lib/Instance.js @@ -123,6 +123,7 @@ function Instance(Model, opts) { }; var afterSave = function (cb, create, err) { emitEvent("save", err, instance); + if (create) { Hook.trigger(instance, opts.hooks.afterCreate, !err); }