From bcd7cb1c5f2d493f44d7f711e9e98addbf03b8a5 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Mon, 9 Nov 2015 19:44:05 -0600 Subject: [PATCH 1/2] Configure copying of attributes and/or relationships. --- addon/mixins/copyable.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addon/mixins/copyable.js b/addon/mixins/copyable.js index 3846966..89b1d97 100644 --- a/addon/mixins/copyable.js +++ b/addon/mixins/copyable.js @@ -3,8 +3,11 @@ import DS from 'ember-data'; export default Ember.Mixin.create({ copyable: true, - copy: function(options) { + copy: function(options, config) { options = options || {}; + config = config || {}; + config.attributes = config.attributes == null ? true : config.attributes; + config.relationships = config.relationships == null ? true : config.relationships; var _this = this; return new Ember.RSVP.Promise(function(resolve) { @@ -14,6 +17,7 @@ export default Ember.Mixin.create({ var queue = []; model.eachAttribute(function(attr) { + if (! config.attributes) { return; } switch(Ember.typeOf(options[attr])) { case 'undefined': copy.set(attr, _this.get(attr)); @@ -27,6 +31,7 @@ export default Ember.Mixin.create({ }); model.eachRelationship(function(relName, meta) { + if (! config.relationships) { return; } var rel = _this.get(relName); if (!rel) { return; } From 891854a2a2cac072d463a361e46bc220d7943c22 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Mon, 9 Nov 2015 23:09:55 -0600 Subject: [PATCH 2/2] Config relationships by kind. --- addon/mixins/copyable.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addon/mixins/copyable.js b/addon/mixins/copyable.js index 89b1d97..9939698 100644 --- a/addon/mixins/copyable.js +++ b/addon/mixins/copyable.js @@ -31,7 +31,15 @@ export default Ember.Mixin.create({ }); model.eachRelationship(function(relName, meta) { - if (! config.relationships) { return; } + var relationships = config.relationships; + if (! relationships) { return; } + if (Ember.typeOf(relationships) === 'string') { + relationships = [relationships]; + } + if (Ember.typeOf(relationships) === 'array' && relationships.indexOf(meta.kind) < 0) { + return; + } + var rel = _this.get(relName); if (!rel) { return; }