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

Fails to update multi-select fields. #73

Open
mbreen opened this issue May 18, 2020 · 2 comments
Open

Fails to update multi-select fields. #73

mbreen opened this issue May 18, 2020 · 2 comments

Comments

@mbreen
Copy link

mbreen commented May 18, 2020

I have a multi-select field that has options: Yes, No, Confirmed.

The field is set to ["Yes"], and I want to be set to ["Yes", "Confirmed"]

I found that I can't just add one - I have to clear it first. So instead of:

contact["Next delivery"].push("Confirmed")
contact.save

I have to do:

result = contact["Next delivery"].push("Confirmed")
contact["Next delivery"] = []
contact["Next delivery"] = result
contact.save
@sirupsen
Copy link
Owner

Please consider submitting a patch

@rcscott
Copy link
Contributor

rcscott commented May 19, 2020

I looked at this briefly and it stems from the way that changes are tracked based on using the = setter method. Making changes directly to an array field doesn't use this method so the @updated_keys value is never changed. I don't see a quick/easy way to solve this.

def []=(key, value)
validate_key(key)
return if fields[key] == value # no-op
@updated_keys << key
fields[key] = value
end

@mbreen you could simplify your code a bit. You don't need to clear out the existing value, you just need to overwrite it with a new array:

contact["Next delivery"] += ["Confirmed"]
=> ["Yes", "Confirmed"]
contact.save

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants