From 9d8629f41f00ecce4cee9d2edd4905b198ab360b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 13 Jun 2014 11:47:34 +1000 Subject: [PATCH] Add producer property model --- app/models/enterprise.rb | 1 + app/models/producer_property.rb | 3 +++ ...0140613004344_create_producer_properties.rb | 18 ++++++++++++++++++ db/schema.rb | 18 +++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/models/producer_property.rb create mode 100644 db/migrate/20140613004344_create_producer_properties.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 3c851bde45..132dafe8a0 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -4,6 +4,7 @@ class Enterprise < ActiveRecord::Base acts_as_gmappable :process_geocoding => false has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup' + has_many :producer_properties, foreign_key: 'producer_id' has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy has_many :distributed_orders, :class_name => 'Spree::Order', :foreign_key => 'distributor_id' belongs_to :address, :class_name => 'Spree::Address' diff --git a/app/models/producer_property.rb b/app/models/producer_property.rb new file mode 100644 index 0000000000..cda2928632 --- /dev/null +++ b/app/models/producer_property.rb @@ -0,0 +1,3 @@ +class ProducerProperty < ActiveRecord::Base + belongs_to :property, class_name: 'Spree::Property' +end diff --git a/db/migrate/20140613004344_create_producer_properties.rb b/db/migrate/20140613004344_create_producer_properties.rb new file mode 100644 index 0000000000..b45b3bed5d --- /dev/null +++ b/db/migrate/20140613004344_create_producer_properties.rb @@ -0,0 +1,18 @@ +class CreateProducerProperties < ActiveRecord::Migration + def change + create_table :producer_properties do |t| + t.string :value + t.references :producer + t.references :property + t.integer :position + t.timestamps + end + + add_index :producer_properties, :producer_id + add_index :producer_properties, :property_id + add_index :producer_properties, :position + + add_foreign_key :producer_properties, :enterprises, column: :producer_id + add_foreign_key :producer_properties, :spree_properties, column: :property_id + end +end diff --git a/db/schema.rb b/db/schema.rb index a40a1414e1..5932749993 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140612020206) do +ActiveRecord::Schema.define(:version => 20140613004344) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -312,6 +312,19 @@ ActiveRecord::Schema.define(:version => 20140612020206) do t.datetime "updated_at", :null => false end + create_table "producer_properties", :force => true do |t| + t.string "value" + t.integer "producer_id" + t.integer "property_id" + t.integer "position" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "producer_properties", ["position"], :name => "index_producer_properties_on_position" + add_index "producer_properties", ["producer_id"], :name => "index_producer_properties_on_producer_id" + add_index "producer_properties", ["property_id"], :name => "index_producer_properties_on_property_id" + create_table "product_distributions", :force => true do |t| t.integer "product_id" t.integer "distributor_id" @@ -1052,6 +1065,9 @@ ActiveRecord::Schema.define(:version => 20140612020206) do add_foreign_key "order_cycles", "enterprises", name: "order_cycles_coordinator_id_fk", column: "coordinator_id" + add_foreign_key "producer_properties", "enterprises", name: "producer_properties_producer_id_fk", column: "producer_id" + add_foreign_key "producer_properties", "spree_properties", name: "producer_properties_property_id_fk", column: "property_id" + add_foreign_key "product_distributions", "enterprise_fees", name: "product_distributions_enterprise_fee_id_fk" add_foreign_key "product_distributions", "enterprises", name: "product_distributions_distributor_id_fk", column: "distributor_id" add_foreign_key "product_distributions", "spree_products", name: "product_distributions_product_id_fk", column: "product_id"