Theocacao
Leopard
Design Element
Comment on "Class Composition in Rails"
by Michael Koziarski — Dec 25
Hi Scott,

I'd also implement 'address' with a one to one relationship, in fact I have quite regularly, I wouldn't consider using composed_of for an address 'best practise'.

I'd say the O'Reilly authors were simply struggling for a use case for composed_of. A less-strange case is for multiple currency support. You probably don't want to have a 'prices' table, so use some composition.

composed_of :price, :class_name => "Money", :mapping => [%w(price amount), %w(currency currency)]
Back to "Class Composition in Rails"
Design Element

Copyright © Scott Stevenson 2004-2015