{"action":"created","issue":{"url":"https://api.github.com/repos/RubyMoney/money-rails/issues/372","labels_url":"https://api.github.com/repos/RubyMoney/money-rails/issues/372/labels{/name}","comments_url":"https://api.github.com/repos/RubyMoney/money-rails/issues/372/comments","events_url":"https://api.github.com/repos/RubyMoney/money-rails/issues/372/events","html_url":"https://github.com/RubyMoney/money-rails/issues/372","id":108316018,"number":372,"title":"Issue with mass assignment of multiple monetized fields","user":{"login":"datibbaw","id":87972,"avatar_url":"https://avatars.githubusercontent.com/u/87972?v=3","gravatar_id":"","url":"https://api.github.com/users/datibbaw","html_url":"https://github.com/datibbaw","followers_url":"https://api.github.com/users/datibbaw/followers","following_url":"https://api.github.com/users/datibbaw/following{/other_user}","gists_url":"https://api.github.com/users/datibbaw/gists{/gist_id}","starred_url":"https://api.github.com/users/datibbaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datibbaw/subscriptions","organizations_url":"https://api.github.com/users/datibbaw/orgs","repos_url":"https://api.github.com/users/datibbaw/repos","events_url":"https://api.github.com/users/datibbaw/events{/privacy}","received_events_url":"https://api.github.com/users/datibbaw/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-25T12:30:56Z","updated_at":"2015-10-26T22:26:19Z","closed_at":"2015-10-19T13:33:38Z","body":"I have a model that has two monetized fields:\r\n\r\n    monetize :minimum_order_free_delivery_cents, :default_delivery_fee_cents, allow_nil: true, with_model_currency: :currency\r\n\r\nThe problem I'm facing is when my record's `new()` or `create()` is called with multiple field assignments, e.g.:\r\n\r\n    country_id: 6\r\n    minimum_order_free_delivery: ''\r\n    default_delivery_fee: '20'\r\n\r\nThe first assignment will implicitly set the model currency (e.g. country 6 uses HKD in our case); the second assignment sets the model currency to nil and the third assignment sets the model currency to the default currency.\r\n\r\nEven if I set the currency after the `new()` is done, the multiplier may be have been wrongly applied at the third assignment.\r\n\r\nMy issue would be resolved if the model currency isn't touched when the money value is set to nil, but I'm open to ideas I haven't discovered yet :)\r\n\r\nOne way I've managed to make this work for now is to add a condition in the setter:\r\n\r\n    def currency=(currency)\r\n      super(currency) if currency\r\n    end\r\n"},"comment":{"url":"https://api.github.com/repos/RubyMoney/money-rails/issues/comments/151302495","html_url":"https://github.com/RubyMoney/money-rails/issues/372#issuecomment-151302495","issue_url":"https://api.github.com/repos/RubyMoney/money-rails/issues/372","id":151302495,"user":{"login":"joekur","id":1043396,"avatar_url":"https://avatars.githubusercontent.com/u/1043396?v=3","gravatar_id":"","url":"https://api.github.com/users/joekur","html_url":"https://github.com/joekur","followers_url":"https://api.github.com/users/joekur/followers","following_url":"https://api.github.com/users/joekur/following{/other_user}","gists_url":"https://api.github.com/users/joekur/gists{/gist_id}","starred_url":"https://api.github.com/users/joekur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joekur/subscriptions","organizations_url":"https://api.github.com/users/joekur/orgs","repos_url":"https://api.github.com/users/joekur/repos","events_url":"https://api.github.com/users/joekur/events{/privacy}","received_events_url":"https://api.github.com/users/joekur/received_events","type":"User","site_admin":false},"created_at":"2015-10-26T22:26:19Z","updated_at":"2015-10-26T22:26:19Z","body":"Here's a very simple fix: https://github.com/RubyMoney/money-rails/compare/master...joekur:instance-currency-assigning-nil"}}