Skip to content

Commit

Permalink
Merge pull request solidusio#538 from cbrunsdon/kill_option_types_habtm
Browse files Browse the repository at this point in the history
Remove option_type_prototype HABTM
  • Loading branch information
cbrunsdon committed Dec 9, 2015
2 parents 5557bc1 + b2779ea commit c9ef429
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/app/models/spree/option_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class OptionType < Spree::Base
has_many :option_values, -> { order(:position) }, dependent: :destroy, inverse_of: :option_type
has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
has_many :products, through: :product_option_types
has_and_belongs_to_many :prototypes, join_table: 'spree_option_types_prototypes'

has_many :option_type_prototypes
has_many :prototypes, through: :option_type_prototypes

validates :name, presence: true, uniqueness: true
validates :presentation, presence: true
Expand Down
6 changes: 6 additions & 0 deletions core/app/models/spree/option_type_prototype.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Spree
class OptionTypePrototype < Spree::Base
belongs_to :option_type
belongs_to :prototype
end
end
4 changes: 3 additions & 1 deletion core/app/models/spree/prototype.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module Spree
class Prototype < Spree::Base
has_and_belongs_to_many :option_types, join_table: :spree_option_types_prototypes

has_many :property_prototypes
has_many :properties, through: :property_prototypes

has_many :option_type_prototypes
has_many :option_types, through: :option_type_prototypes

has_many :prototype_taxons, dependent: :destroy
has_many :taxons, through: :prototype_taxons

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ConvertHabtmToHmtForOptionTypePrototypes < ActiveRecord::Migration
def up
add_column :spree_option_types_prototypes, :id, :primary_key
add_column :spree_option_types_prototypes, :created_at, :datetime
add_column :spree_option_types_prototypes, :updated_at, :datetime

rename_table :spree_option_types_prototypes, :spree_option_type_prototypes
end

def down
remove_column :spree_option_types_prototypes, :id
remove_column :spree_option_types_prototypes, :created_at
remove_column :spree_option_types_prototypes, :updated_at

rename_table :spree_option_type_prototypes, :spree_option_types_prototypes
end
end

0 comments on commit c9ef429

Please sign in to comment.