Skip to content
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 · Fixed by #5058
Closed

'fields' option modifies passed object #4520

Malgalad opened this issue Sep 16, 2015 · 1 comment · Fixed by #5058
Labels
good first issue For issues. An issue that is a good choice for first-time contributors. type: bug

Comments

@Malgalad
Copy link

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
Copy link
Member

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

@janmeier janmeier added the good first issue For issues. An issue that is a good choice for first-time contributors. label Sep 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue For issues. An issue that is a good choice for first-time contributors. type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants