diff --git a/lib/model-builder.js b/lib/model-builder.js index 708d328b..df46130e 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -439,7 +439,14 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett if (mixin === true) { mixin = {}; } - if (typeof mixin === 'object') { + if (Array.isArray(mixin)) { + mixin.forEach(function(m) { + if (m === true) m = {}; + if (typeof m === 'object') { + modelBuilder.mixins.applyMixin(ModelClass, name, m); + } + }); + } else if (typeof mixin === 'object') { modelBuilder.mixins.applyMixin(ModelClass, name, mixin); } } diff --git a/test/mixins.test.js b/test/mixins.test.js index e60f7e02..49a1634a 100644 --- a/test/mixins.test.js +++ b/test/mixins.test.js @@ -49,7 +49,11 @@ describe('Model class', function () { }; }); mixins.define('Demo', function(Model, options) { - Model.demoMixin = options.ok; + Model.demoMixin = options.value; + }); + mixins.define('Multi', function(Model, options) { + Model.multiMixin = Model.multiMixin || {}; + Model.multiMixin[options.key] = options.value; }); }); @@ -73,13 +77,22 @@ describe('Model class', function () { it('should apply mixins', function(done) { var memory = new DataSource('mem', {connector: Memory}, modelBuilder); var Item = memory.createModel('Item', { name: 'string' }, { - mixins: { TimeStamp: true, Demo: { ok: true } } + mixins: { + TimeStamp: true, Demo: { value: true }, + Multi: [ + { key: 'foo', value: 'bar' }, + { key: 'fox', value: 'baz' } + ] + } }); Item.mixin('Example', { foo: 'bar' }); Item.demoMixin.should.be.true; + Item.multiMixin.foo.should.equal('bar'); + Item.multiMixin.fox.should.equal('baz'); + var properties = Item.definition.properties; properties.createdAt.should.eql({ type: Date }); properties.updatedAt.should.eql({ type: Date });