backbone-associations icon indicating copy to clipboard operation
backbone-associations copied to clipboard

Cloning populates the attributes from json which can contain remoteKey

Open gfrivolt opened this issue 10 years ago • 1 comments

Probably there is a reason for this implementation, but in case of a relation with a remoteKey the cloned model is not going to have the same attributes as the original.

    clone: function (options) {
        return new this.constructor(this.toJSON(options));
    }

Also if toJSON is overridden for whatever reason, this clone method does not help. What's the reason to have this cloning instead of the Backbone's clone?

gfrivolt avatar Sep 30 '14 13:09 gfrivolt

A workaround that worked for me is:

new MyModel(otherModel.attributes)

fqxp avatar Jun 06 '17 09:06 fqxp