-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for copying to an object other than models #13
Comments
This is the same reason I am currently looking into this addon. I do think that it will be helpful to have the ability to return a POJO. @offirgolan let me know if this is something that you would be interested in and I can create a pull request. |
@offirgolan our team is very interested in this feature request. In our use-case, we want to be able to copy a model's attributes, cache them for an extended period of time (local storage), and then apply the cached attributes at a later date to create a new record. We're thinking something along the lines of the following API: // Copy Attributes Usage
const model = this.get('store').peekRecord('user', 1);
// setting attributesOnly option will return an object of attributes
const attributes = await model
.copy(true, { attributesOnly: true })
// applyCopyAttributes method accepts object to set attributes and create relationships
const record = await this.store.createRecord('user')
.applyCopyAttributes(attributes)
.save(); Would you be open to accepting a PR for this work? |
@flexyford PR is always welcome. Is |
When ever we edit a model, we make a copy first to an object, then edit that. This means that a cancel just throws the object away. To help this all computed properties are put in a mixin, only data fields are put in the model. This allows us to add the mixin to an object and simulate the model.
It would be nice to be able to use this addon to copy the data to an object instead of a new model and it looks like that could happen with a very small change where you create the model. It would have been nice if there was a method that just created the attr hash and then used that to apply. That also is easily doable except for the code at 194 using the private API. What is that accomplishing that the attrs[name] = this.get(name); didnt accomplish?
It would also be nice to expose the attrs[] because I could use that to copy the object back to the original model.
The text was updated successfully, but these errors were encountered: