This is fairly niche and I have work arounds, but I figured I'd bring this up just in case there is an easy fix
Assuming the following models:
Class Product < ApplicationRecord
# has attribute currency
has_many :variants
end
Class Variant < ApplicationRecord
belongs_to :product
monetize :price_cents, with_currency: ->(variant) { variant.product.currency }
end
then when creating a variant through the relationship like this assuming a product with currency = "KRW" (South Korean Won - a currency without subunits):
@product.variants.new(price: 20)
I get back a variant with price_cents set to 2000 when it should only be 20 since KRW units and subunits should be equal.
Seems like :price_cents is being converted from :price with the default system currency when the currency through the relationship to product should be used
This is fairly niche and I have work arounds, but I figured I'd bring this up just in case there is an easy fix
Assuming the following models:
then when creating a variant through the relationship like this assuming a product with currency = "KRW" (South Korean Won - a currency without subunits):
@product.variants.new(price: 20)
I get back a variant with price_cents set to 2000 when it should only be 20 since KRW units and subunits should be equal.
Seems like :price_cents is being converted from :price with the default system currency when the currency through the relationship to product should be used