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

'fields' option modifies passed object #4520

Closed
Malgalad opened this Issue Sep 16, 2015 · 1 comment

Comments

2 participants
@Malgalad

Malgalad commented Sep 16, 2015

Suppose we have

var obj = {a: 1, b: 2, c: 3}

and we want to update some model with it but pick only specific fields, and then we want to update other model with the same object, but with different fields:

some_model.update(obj, {fields: ['a', 'b']});

other_model.update(obj, {fields: ['c']}) // Error: column 'c' cannot be null

console.log(obj); // {a: 1, b: 2};

What happened? - First update function picked fields a and b, but instead of working with a clone of obj, it modified it.

Is it intended behaviour? The obvious workaround would be to clone obj manually before passing it to update function, but I think this is not intuitive.

@janmeier janmeier added the bug label Sep 16, 2015

@janmeier

This comment has been minimized.

Member

janmeier commented Sep 16, 2015

Yeah, the value object should probably be cloned - PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment