
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
ember-data-copyable
Advanced tools
Intelligently copy an Ember Data model and all of its relationships
Intelligently copy an Ember Data model and all of its relationships
ember install ember-data-copyable
If it is a bug please open an issue on GitHub.
This addon provides a Copyable mixin which allows you to copy a model. To get started,
just import the mixin and add it to your model.
// models/user.js
import DS from 'ember-data';
import Copyable from 'ember-data-copyable';
export default DS.Model.extend(Copyable, {
guid: DS.attr('number'),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
address: DS.belongsTo('address'),
friends: DS.hasMany('user'),
// Specific copy options for the model
copyableOptions: {}
});
In your model you can specify default options via the copyableOptions object.
Please see options for more details.
To copy a model's relationship, that relational model must have the Copyable mixin or else it will just
be copied by reference.
Once the model is setup, we can use the copy method on an instance to duplicate it.
async function copy(deep = false, options = {}) {}
deep : Boolean
If false a shallow copy of the model's attributes will be created. All relationships will be copied over by reference.
If true, a deep copy of the model and it's relationships will be created. If a relational model has the Copyable mixin, it will also be deep copied.
options : Object
Copy options. See options for more details.
NOTE: Options passed into the copy method take precedence over those specified on the model.
Returns a cancelable promise like ember-concurrency TaskInstance.
const model = this.get('store').peekRecord('user', 1);
model
.copy(true, {
ignoreAttributes: ['guid'],
copyByReference: ['address'],
overwrite: {
id: 2,
firstName: 'Offir'
}
})
.then(
copy => {
// Handle success
return copy.save();
},
e => {
// Handle error or cancellation
}
);
Since the copy method returns an ember-concurrency TaskInstance,
we have the ability to cancel a running copy task at any time.
const model = this.get('store').peekRecord('user', 1);
const copyTaskInstance = model.copy(true);
// Cancel our copy task
copyTaskInstance.cancel();
These options can either be specified via the copyableOptions object on the DS.Model class or
passed into the copy method.
ignoreAttributesAttributes to ignore when copying.
ignoreAttributes: ['guid', 'address'];
otherAttributesOther attributes to copy over that are not defined via DS.attr, DS.belongsTo, or DS.hasMany.
otherAttributes: ['timestamp', 'someFlag'];
copyByReferenceAttributes to copy only by reference. If the attribute has the Copyable mixin, it will
be ignored and not be copied, just copied by reference.
copyByReference: ['friends'];
overwriteOverwrite attributes with the specified values. This will also add properties that are not found on the model.
overwrite: {
id: 2,
firstName: 'Offir - Copy',
address: this.get('store').createRecord('address', { /* ... */ }),
unknownProperty: 'Foo Bar'
}
relationshipsSpecify options to nested models.
Nested relationships options can also include a deep option. If set to false,
the relationship will be shallow copied.
relationships: {
address: {
ignoreAttributes: ['streetName'],
overwrite: {
state: 'CA'
}
},
friends: {
copyByReference: ['address']
},
profile: {
deep: false
}
}
FAQs
Intelligently copy an Ember Data model and all of its relationships
The npm package ember-data-copyable receives a total of 3,153 weekly downloads. As such, ember-data-copyable popularity was classified as popular.
We found that ember-data-copyable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.