dhruvaray / backbone-associations

Create object hierarchies with Backbone models; Respond to hierarchy changes using regular Backbone events.
http://dhruvaray.github.io/backbone-associations/
MIT License
492 stars 75 forks source link

Cloning populates the attributes from json which can contain remoteKey #151

Open gfrivolt opened 9 years ago

gfrivolt commented 9 years ago

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?

fqxp commented 7 years ago

A workaround that worked for me is:

new MyModel(otherModel.attributes)