Topic: Database update with has_many relationship
I need to do an update on my database where an Project has_many :costs. If there is a cost with :year equal to 0 I need to set :old_cost in Project to the value of :cost in the Cost.
That sounds like garbage so time for some code.
class Project :old_cost has_may :costs end class Cost belongs_to :project :year :cost end
I have tries looking at update_all but that didn't seem suitable for this and I tried looping through projects and then costs in the rails console and doing an if inside that but the resulting SQL was just a SELECT not and UPDATE.
Thanks for any help