{"id":15459132,"url":"https://github.com/offirgolan/ember-data-copyable","last_synced_at":"2025-05-12T14:29:22.869Z","repository":{"id":21478868,"uuid":"92461874","full_name":"offirgolan/ember-data-copyable","owner":"offirgolan","description":"Intelligently copy an Ember Data model and all of its relationships","archived":false,"fork":false,"pushed_at":"2023-12-22T17:40:45.000Z","size":1778,"stargazers_count":45,"open_issues_count":14,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-12T14:29:12.872Z","etag":null,"topics":["copy","duplicate","ember","ember-addon","ember-data"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/offirgolan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-26T02:04:22.000Z","updated_at":"2024-05-30T02:27:41.000Z","dependencies_parsed_at":"2023-12-22T18:32:49.875Z","dependency_job_id":"994f766c-1954-4117-8592-6e86c8918053","html_url":"https://github.com/offirgolan/ember-data-copyable","commit_stats":{"total_commits":53,"total_committers":12,"mean_commits":4.416666666666667,"dds":"0.37735849056603776","last_synced_commit":"b5c815c9c2d8a7520e817e4d67a0ae17cbd9b314"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offirgolan%2Fember-data-copyable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offirgolan%2Fember-data-copyable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offirgolan%2Fember-data-copyable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offirgolan%2Fember-data-copyable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/offirgolan","download_url":"https://codeload.github.com/offirgolan/ember-data-copyable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253754737,"owners_count":21958901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["copy","duplicate","ember","ember-addon","ember-data"],"created_at":"2024-10-01T23:04:52.178Z","updated_at":"2025-05-12T14:29:22.838Z","avatar_url":"https://github.com/offirgolan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ember Data Copyable\n\n[![Build Status](https://travis-ci.org/offirgolan/ember-data-copyable.svg?branch=master)](https://travis-ci.org/offirgolan/ember-data-copyable)\n[![npm version](https://badge.fury.io/js/ember-data-copyable.svg)](http://badge.fury.io/js/ember-data-copyable)\n\nIntelligently copy an Ember Data model and all of its relationships\n\n## Features\n\n- Shallow \u0026 deep copy an Ember Data model\n- Shallow \u0026 deep copy model relationships\n- Handles cyclical relationships\n- Handles custom transforms to create true copies\n- Overwrite, ignore attributes, and copy objects by reference\n- Intelligent failure and cleanup\n- Uses [ember-concurrency](https://github.com/machty/ember-concurrency) to allow cancelling a copy task\n\n## Installation\n\n```\nember install ember-data-copyable\n```\n\n## Helpful Links\n\n- ### [Changelog](CHANGELOG.md)\n\n## Looking for help?\n\nIf it is a bug [please open an issue on GitHub](http://github.com/offirgolan/ember-data-copyable/issues).\n\n## Setup\n\nThis addon provides a `Copyable` mixin which allows you to copy a model. To get started,\njust import the mixin and add it to your model.\n\n```js\n// models/user.js\n\nimport DS from 'ember-data';\nimport Copyable from 'ember-data-copyable';\n\nexport default DS.Model.extend(Copyable, {\n  guid: DS.attr('number'),\n  firstName: DS.attr('string'),\n  lastName: DS.attr('string'),\n  address: DS.belongsTo('address'),\n  friends: DS.hasMany('user'),\n\n  // Specific copy options for the model\n  copyableOptions: {}\n});\n```\n\nIn your model you can specify default options via the `copyableOptions` object.\nPlease see [options](#options) for more details.\n\n### Copying Relationships\n\nTo copy a model's relationship, that relational model **must** have the `Copyable` mixin or else it will just\nbe copied by reference.\n\n## Usage\n\nOnce the model is setup, we can use the `copy` method on an instance to duplicate it.\n\n### Copy Method Signature\n\n```js\nasync function copy(deep = false, options = {}) {}\n```\n\n- `deep` : _Boolean_\n\n  If **false** a shallow copy of the model's attributes will be created.\n  All relationships will be copied over by reference.\n\n  If **true**, a deep copy of the model and it's relationships will be created.\n  If a relational model has the Copyable mixin, it will also be deep copied.\n\n- `options` : _Object_\n\n  Copy options. See [options](#options) for more details.\n\n  **NOTE:** Options passed into the copy method take precedence over those specified on the model.\n\nReturns a cancelable promise like [ember-concurrency](https://github.com/machty/ember-concurrency) TaskInstance.\n\n### Examples\n\n#### Normal Usage\n\n```js\nconst model = this.get('store').peekRecord('user', 1);\n\nmodel\n  .copy(true, {\n    ignoreAttributes: ['guid'],\n    copyByReference: ['address'],\n    overwrite: {\n      id: 2,\n      firstName: 'Offir'\n    }\n  })\n  .then(\n    copy =\u003e {\n      // Handle success\n      return copy.save();\n    },\n    e =\u003e {\n      // Handle error or cancellation\n    }\n  );\n```\n\n#### Task Cancellation\n\nSince the `copy` method returns an [ember-concurrency](https://github.com/machty/ember-concurrency) TaskInstance,\nwe have the ability to cancel a running copy task at any time.\n\n```js\nconst model = this.get('store').peekRecord('user', 1);\nconst copyTaskInstance = model.copy(true);\n\n// Cancel our copy task\ncopyTaskInstance.cancel();\n```\n\n## Options\n\nThese options can either be specified via the `copyableOptions` object on the DS.Model class or\npassed into the `copy` method.\n\n### `ignoreAttributes`\n\nAttributes to ignore when copying.\n\n```js\nignoreAttributes: ['guid', 'address'];\n```\n\n### `otherAttributes`\n\nOther attributes to copy over that are not defined via DS.attr, DS.belongsTo,\nor DS.hasMany.\n\n```js\notherAttributes: ['timestamp', 'someFlag'];\n```\n\n### `copyByReference`\n\nAttributes to copy only by reference. If the attribute has the `Copyable` mixin, it will\nbe ignored and not be copied, just copied by reference.\n\n```js\ncopyByReference: ['friends'];\n```\n\n### `overwrite`\n\nOverwrite attributes with the specified values. This will also add properties\nthat are not found on the model.\n\n```js\noverwrite: {\n  id: 2,\n  firstName: 'Offir - Copy',\n  address: this.get('store').createRecord('address', { /* ... */ }),\n  unknownProperty: 'Foo Bar'\n}\n```\n\n### `relationships`\n\nSpecify options to nested models.\nNested relationships options can also include a `deep` option. If set to false,\nthe relationship will be shallow copied.\n\n```js\nrelationships: {\n  address: {\n    ignoreAttributes: ['streetName'],\n    overwrite: {\n      state: 'CA'\n    }\n  },\n  friends: {\n    copyByReference: ['address']\n  },\n  profile: {\n    deep: false\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffirgolan%2Fember-data-copyable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffirgolan%2Fember-data-copyable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffirgolan%2Fember-data-copyable/lists"}