Ember Data Copyable
Intelligently copy an Ember Data model and all of its relationships
- Shallow & deep copy an Ember Data model
- Shallow & deep copy model relationships
- Handles cyclical relationships
- Handles custom transforms to create true copies
- Overwrite, ignore attributes, and copy objects by reference
- Intelligent failure and cleanup
- Uses ember-concurrency to allow cancelling a copy task
ember install ember-data-copyable
- ### Changelog
Looking for help?
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.
In your model you can specify default options via the
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.
Copy Method Signature
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.
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;model;
copy method returns an ember-concurrency TaskInstance,
we have the ability to cancel a running copy task at any time.
const model = this;const copyTaskInstance = model;// Cancel our copy taskcopyTaskInstance;
These options can either be specified via the
copyableOptions object on the DS.Model class or
passed into the
Attributes to ignore when copying.
ignoreAttributes: 'guid' 'address';
Other attributes to copy over that are not defined via DS.attr, DS.belongsTo, or DS.hasMany.
otherAttributes: 'timestamp' 'someFlag';
Attributes to copy only by reference. If the attribute has the
Copyable mixin, it will
be ignored and not be copied, just copied by reference.
Overwrite attributes with the specified values. This will also add properties that are not found on the model.
overwrite:id: 2firstName: 'Offir - Copy'address: thisunknownProperty: 'Foo Bar'
Specify 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