Add EnterpriseRole model and link up to users and enterprises.

This commit is contained in:
Andrew Spinks
2013-07-31 16:00:28 +10:00
parent 5810503068
commit 4f5679aac3
7 changed files with 29 additions and 10 deletions

View File

@@ -4,6 +4,8 @@ class Enterprise < ActiveRecord::Base
belongs_to :address, :class_name => 'Spree::Address'
has_many :product_distributions, :foreign_key => 'distributor_id', :dependent => :destroy
has_many :distributed_products, :through => :product_distributions, :source => :product
has_many :enterprise_roles
has_many :users, through: :enterprise_roles
accepts_nested_attributes_for :address

View File

@@ -0,0 +1,4 @@
class EnterpriseRole < ActiveRecord::Base
belongs_to :user, :class_name => Spree.user_class
belongs_to :enterprise
end

View File

@@ -0,0 +1,4 @@
Spree.user_class.class_eval do
has_many :enterprise_roles, :dependent => :destroy
has_many :enterprises, through: :enterprise_roles
end

View File

@@ -0,0 +1,8 @@
class AddEnterpriseRole < ActiveRecord::Migration
def change
create_table :enterprise_roles do |t|
t.references :user, index: true
t.references :enterprise, index: true
end
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 => 20130729021924) do
ActiveRecord::Schema.define(:version => 20130729030515) do
create_table "cms_blocks", :force => true do |t|
t.integer "page_id", :null => false
@@ -130,11 +130,6 @@ ActiveRecord::Schema.define(:version => 20130729021924) 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"
@@ -143,6 +138,11 @@ ActiveRecord::Schema.define(:version => 20130729021924) do
t.datetime "updated_at", :null => false
end
create_table "enterprise_roles", :force => true do |t|
t.integer "user_id"
t.integer "enterprise_id"
end
create_table "enterprises", :force => true do |t|
t.string "name"
t.string "description"
@@ -194,8 +194,10 @@ ActiveRecord::Schema.define(:version => 20130729021924) do
t.datetime "orders_open_at"
t.datetime "orders_close_at"
t.integer "coordinator_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "coordinator_admin_fee_id"
t.integer "coordinator_sales_fee_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "product_distributions", :force => true do |t|

View File

@@ -6,6 +6,7 @@ namespace :openfoodweb do
desc 'load sample data'
task :load_sample_data => :environment do
require File.expand_path('../../../spec/factories', __FILE__)
require File.expand_path('../../../spec/support/spree/init', __FILE__)
# -- Shipping / payment information
unless Spree::Zone.find_by_name 'Australia'

View File

@@ -1,5 +1,3 @@
require 'factory_girl_rails'
# Initialise shipping method when created without one, like this:
# create(:product, :distributors => [...])
# In this case, we don't care what the shipping method is, but we need one for validations to pass.