From 016cb0b21d4eff4b92c25775d01ab05c7457f57a Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Mon, 9 Jan 2012 15:48:20 +0100 Subject: [PATCH] Added company info revisioning in the models (refs: #ba1a26) * Extended CompanyInfo with an "original" association with the previous revision (in case revisions can be removed in the future). * Created a belongs_to relation of Invoice with CompanyInfo and an has_many reverse relation. --- stoptime.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index f91963a..ee0c4dc 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -311,6 +311,7 @@ module StopTime::Models # # === Attributes by association # + # [company_info] associated company info (CompanyInfo) # [customer] associated customer (Customer) # [tasks] billed tasks by the invoice (Array of Task) # [time_entries] billed time entries (Array of TimeEntry) @@ -318,6 +319,7 @@ module StopTime::Models has_many :tasks has_many :time_entries, :through => :tasks belongs_to :customer + belongs_to :company_info # Returns a time and cost summary of the contained tasks (Hash of # Task to Array). @@ -371,7 +373,19 @@ module StopTime::Models # [accountiban] international bank account number (String) # [created_at] time of creation (Time) # [updated_at] time of last update (Time) + # + # === Attributes by association + # + # [invoices] associated invoices (Array of Invoice) + # [original] original (previous) revision (CompanyInfo) class CompanyInfo < Base + belongs_to :original, :class_name => "CompanyInfo" + has_many :invoices + + # Returns the revision number (Fixnum). + def revision + id + end end class StopTimeTables < V 1.0 # :nodoc: @@ -559,6 +573,23 @@ module StopTime::Models end end + class CompanyInfoRevisioning < V 1.93 # :nodoc: + def self.up + add_column(CompanyInfo.table_name, :original_id, :integer) + add_column(Invoice.table_name, :company_info_id, :integer) + ci = CompanyInfo.last + Invoice.all.each do |i| + i.company_info = ci + i.save + end + end + + def self.down + remove_column(CompanyInfo.table_name, :original_id) + remove_column(Invoice.table_name, :company_info_id) + end + end + end # StopTime::Models # = The Stop… Camping Time! controllers