Add producer property model

This commit is contained in:
Rohan Mitchell
2014-06-13 11:47:34 +10:00
parent 6809d70397
commit 9d8629f41f
4 changed files with 39 additions and 1 deletions

View File

@@ -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'

View File

@@ -0,0 +1,3 @@
class ProducerProperty < ActiveRecord::Base
belongs_to :property, class_name: 'Spree::Property'
end

View File

@@ -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

View File

@@ -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"