I have a System
class with an attr called price
and a Subsystem
class (belongs_to :system
) with also this price
attr.
The problem is in my model, because I have two different ways of treating the system.price
1) The system has at least one subsystem (!system.subsystems.empty?
): I want the price to be the sum of all it's subsystems prices. In that case, my model has it's method price with a loop to sum the subsystems prices.
2) The system doesn't have ANY subsystem (system.subsystems.empty?
): The price is simply an input field which it's filled in a form.
The trouble i'm facing is how to 'choose' which way to follow...
Can anyone help me? Thks a lot in advance!!!