RubyMoney/money-rails

Using with_model_currency While Referencing Currency on Associated Record

Closed this issue ยท 2 comments

Hi all ๐Ÿ‘‹

I'm looking at a use case where I define a currency on one record, and then I would want to reference that currency on that record in associated records.

This works using with_model_currency: :currency and delegating the :currency method to the associated model, but wanted to see if there was a more elegant way to do this.

class Product < ApplicationRecord
  monetize :price_cents, with_model_currency: :currency

  belongs_to :shop

  delegate :currency, to: :shop
end

I guess there could be some kind of with_delegated_currency: :shop, but I find the code you have right now already quite short and elegant.

@sunny The more I think about it (and hear feedback from the team), the more I am inclined to agree ๐Ÿ‘