mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Add EnterpriseRole model and link up to users and enterprises.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
4
app/models/enterprise_role.rb
Normal file
4
app/models/enterprise_role.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class EnterpriseRole < ActiveRecord::Base
|
||||
belongs_to :user, :class_name => Spree.user_class
|
||||
belongs_to :enterprise
|
||||
end
|
||||
4
app/models/spree/user_decorator.rb
Normal file
4
app/models/spree/user_decorator.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Spree.user_class.class_eval do
|
||||
has_many :enterprise_roles, :dependent => :destroy
|
||||
has_many :enterprises, through: :enterprise_roles
|
||||
end
|
||||
8
db/migrate/20130729030515_add_enterprise_role.rb
Normal file
8
db/migrate/20130729030515_add_enterprise_role.rb
Normal 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
|
||||
18
db/schema.rb
18
db/schema.rb
@@ -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|
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user