-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexotic_models.rb
65 lines (55 loc) · 1.64 KB
/
exotic_models.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'rubygems'
require 'pp'
require 'active_record'
require 'logger'
require 'ar-extensions'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:database => "clearsenses_v4"
)
#migration
class CreateProductSpecialSubcategory < ActiveRecord::Migration
def self.up
create_table :products_special_subcategories, :id => false do |t|
t.string :product_id
t.string :special_subcategory_id
t.timestamps
end
end
def self.down
drop_table :products_special_subcategories
end
end
# models
class Product < ActiveRecord::Base
set_table_name "product"
set_primary_key "id"
belongs_to :category
has_and_belongs_to_many :subcategories, :join_table => "product_subcategories"
has_and_belongs_to_many :special_subcategories, :join_table => "products_special_subcategories"
end
class Category < ActiveRecord::Base
has_many :subcategories, :dependent=> :destroy
has_many :products
end
class Subcategory < ActiveRecord::Base
belongs_to :category
has_and_belongs_to_many :products, :join_table => "product_subcategories"
has_many :special_subcategories
end
class SpecialSubcategory < ActiveRecord::Base
set_table_name :specialbrowse_links_new
belongs_to :subcategory
has_and_belongs_to_many :products, :join_table => "products_special_subcategories"
end
class ProductReview < ActiveRecord::Base
set_table_name :product_reviews
end
class ArticleReview < ActiveRecord::Base
set_table_name :article_reviews
end
class ArticleNew < ActiveRecord::Base
set_table_name :articles_new
end