mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Change product-distributor relation to *..*
This commit is contained in:
@@ -3,6 +3,7 @@ module Spree
|
||||
self.table_name = 'distributors'
|
||||
belongs_to :country
|
||||
belongs_to :state
|
||||
has_and_belongs_to_many :products
|
||||
|
||||
validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Spree::Product.class_eval do
|
||||
belongs_to :supplier
|
||||
has_and_belongs_to_many :distributors
|
||||
|
||||
attr_accessible :supplier_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
class MoveDistributorFromOrderToProduct < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
remove_column :spree_orders, :distributor_id
|
||||
add_column :spree_products, :distributor_id, :integer
|
||||
Spree::Order.reset_column_information
|
||||
Spree::Product.reset_column_information
|
||||
|
||||
# Associate all products with the first distributor so they'll be valid
|
||||
create_table :distributors_products, :id => false do |t|
|
||||
t.references :product
|
||||
t.references :distributor
|
||||
end
|
||||
|
||||
# Associate all products with the first distributor
|
||||
distributor = Spree::Distributor.first
|
||||
Spree::Product.update_all("distributor_id = #{distributor.id}") if distributor
|
||||
if distributor
|
||||
Spree::Product.all.each do |product|
|
||||
product.distributors << distributor
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :distributors_products
|
||||
add_column :spree_orders, :distributor_id, :integer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,6 +32,11 @@ ActiveRecord::Schema.define(:version => 20120618061537) do
|
||||
t.integer "state_id"
|
||||
end
|
||||
|
||||
create_table "distributors_products", :id => false, :force => true do |t|
|
||||
t.integer "product_id"
|
||||
t.integer "distributor_id"
|
||||
end
|
||||
|
||||
create_table "spree_activators", :force => true do |t|
|
||||
t.string "description"
|
||||
t.datetime "expires_at"
|
||||
@@ -353,7 +358,6 @@ ActiveRecord::Schema.define(:version => 20120618061537) do
|
||||
t.datetime "updated_at"
|
||||
t.integer "count_on_hand", :default => 0, :null => false
|
||||
t.integer "supplier_id"
|
||||
t.integer "distributor_id"
|
||||
end
|
||||
|
||||
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"
|
||||
|
||||
@@ -4,6 +4,7 @@ describe Spree::Product do
|
||||
|
||||
describe "associations" do
|
||||
it { should belong_to(:supplier) }
|
||||
it { should have_and_belong_to_many(:distributors) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user