Make order cycle coordinator fees many-to-many

This commit is contained in:
Rohan Mitchell
2013-07-29 13:20:35 +10:00
parent bb9368a1b2
commit 122b9b5617
4 changed files with 29 additions and 9 deletions

View File

@@ -1,7 +1,6 @@
class OrderCycle < ActiveRecord::Base
belongs_to :coordinator, :class_name => 'Enterprise'
belongs_to :coordinator_admin_fee, :class_name => 'EnterpriseFee'
belongs_to :coordinator_sales_fee, :class_name => 'EnterpriseFee'
has_and_belongs_to_many :coordinator_fees, :class_name => 'EnterpriseFee', :join_table => 'coordinator_fees'
has_many :exchanges, :dependent => :destroy

View File

@@ -0,0 +1,19 @@
class MakeOrderCycleCoordinatorFeesMtm < ActiveRecord::Migration
def up
remove_column :order_cycles, :coordinator_admin_fee_id
remove_column :order_cycles, :coordinator_sales_fee_id
create_table :coordinator_fees, id: false do |t|
t.references :order_cycle
t.references :enterprise_fee
end
end
def down
drop_table :coordinator_fees
add_column :order_cycles, :coordinator_admin_fee_id, :integer
add_column :order_cycles, :coordinator_sales_fee_id, :integer
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130629120645) do
ActiveRecord::Schema.define(:version => 20130729021924) do
create_table "cms_blocks", :force => true do |t|
t.integer "page_id", :null => false
@@ -130,6 +130,11 @@ ActiveRecord::Schema.define(:version => 20130629120645) do
add_index "cms_snippets", ["site_id", "identifier"], :name => "index_cms_snippets_on_site_id_and_identifier", :unique => true
add_index "cms_snippets", ["site_id", "position"], :name => "index_cms_snippets_on_site_id_and_position"
create_table "coordinator_fees", :id => false, :force => true do |t|
t.integer "order_cycle_id"
t.integer "enterprise_fee_id"
end
create_table "enterprise_fees", :force => true do |t|
t.integer "enterprise_id"
t.string "fee_type"
@@ -189,10 +194,8 @@ ActiveRecord::Schema.define(:version => 20130629120645) do
t.datetime "orders_open_at"
t.datetime "orders_close_at"
t.integer "coordinator_id"
t.integer "coordinator_admin_fee_id"
t.integer "coordinator_sales_fee_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "product_distributions", :force => true do |t|

View File

@@ -15,8 +15,7 @@ describe OrderCycle do
oc = create(:simple_order_cycle)
oc.coordinator = create(:enterprise)
oc.coordinator_admin_fee = create(:enterprise_fee)
oc.coordinator_sales_fee = create(:enterprise_fee)
oc.coordinator_fees << create(:enterprise_fee, enterprise: oc.coordinator)
oc.save!
end