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

Instance.reload() breaking changes 2.x -> 3.x #3976

Closed
defunctzombie opened this Issue Jun 19, 2015 · 7 comments

Comments

2 participants
@defunctzombie
Contributor

defunctzombie commented Jun 19, 2015

It seems that it is no longer possible to reload only a specific field when calling instance.reload(). I use to accomplish this by passing an array of fields to reload to reload(). I attempted to follow the docs and pass { attributes: ['field_to_reload'] } however when performing a subsequent save and specifying a single attribute to save I am presented with the following error:

You attempted to save an instance with no primary key, this is not allowed since it would result in a global update

This leads me to believe that the instance reload for a specific attribute either 1) did not work or 2) reloaded that attribute but cleared out the previous values for other attributes.

If it is not possible to reload only a specific field that is fine (just worth noting in the reload docs). If it is desired functionality (rare but useful since in my case I know I just want a fresher version of a single field) then this seems like a bug.

Additionally, might be worth noting in the 3.x changelog that instance reload is another place there breaking changes might happen since the arguments from it are passed to find.

@mickhansen mickhansen added the bug label Jun 21, 2015

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jun 21, 2015

fields: [] should still be supported. If it isn't we had a regression.
I imagine that we call set with reset: true with the new data values and since you only select a subset it whipes out the entire dataset and only sets the single field, should be simple enough to fix (only reset if fields is undefined`)

@defunctzombie

This comment has been minimized.

Contributor

defunctzombie commented Jun 22, 2015

Ok, fields does work. The reason I had not tried that (I was actually using attributes) was because the reload documentation said that the options were passed to Model.find so I went and looked at the findAll documentation and that only mentioned the attributes field. fields only appears in the create documentation it seems.

tl;dr; documentation bug/clarity issues around what options are available to the reload method.

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jun 22, 2015

Hmm you are right fields is actually only for create'. attributes` should work for reload/findOne, but yeah i imagine it doesn't.

@defunctzombie

This comment has been minimized.

Contributor

defunctzombie commented Jun 22, 2015

attributes does not work. And now that I think about it, fields "working" might have just been that it was ignored and the whole model was loaded.

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jun 22, 2015

Yeah i think that might have been the case aswell. Definitely a regression.

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jun 23, 2015

Fixed in 3.3.1

@defunctzombie

This comment has been minimized.

Contributor

defunctzombie commented Jun 23, 2015

Thanks!

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