RubyMoney / money-rails

Integration of RubyMoney - Money with Rails
MIT License
1.79k stars 386 forks source link

Support for One Currency / Multiple Cents Columns per Record? #678

Closed chase-stevens closed 10 months ago

chase-stevens commented 11 months ago

Hi all 👋

I wanted to reach out in regards for the migration helper method add_monetize for the case where a record has a single attribute for currency and multiple different cents attributes.

I'm able to set this up by adding integer columns for my *_cents attributes and a string column for my currency attribute and using the with_model_currency argument with monetize in the model.

I was wondering if there was more support or a more elegant way of going about this? Initially, I tried to use the column_name argument in the initializer for currency to set all currency columns generated by add_monetize to use the same column, but that resulted in a DuplicateColumn error. Would there be any interest in allowing for skipping creating duplicate columns if the column name argument is set?

Thanks and please let me know if you have any questions.

sunny commented 11 months ago

For these use cases I’ve been adding the _cents columns using add_column instead of using add_monetize.

From my understanding you can also do add_monetize …, currency: false, although it is not documented.

chase-stevens commented 10 months ago

Thanks @sunny, appreciate it. In our RFC, we're recommending adding each column separately as our standard is to use one currency column per model. We do have some use cases where want a currency column for each attribute, but those are rarer.