Permalink
Browse files

setup relations in models + indexes on foreign keys

  • Loading branch information...
1 parent e23ec11 commit c1d3286fba8cc4d2c8f246d8960a582ba49a6313 @jsjohnst committed Dec 21, 2009
View
@@ -1,2 +1,4 @@
class Checkout < ActiveRecord::Base
+ belongs_to :users
+ belongs_to :medias
end
View
@@ -1,2 +1,4 @@
class Downloads < ActiveRecord::Base
+ belongs_to :users
+ belongs_to :medias
end
View
@@ -1,2 +1,3 @@
class Item < ActiveRecord::Base
+ has_many :medias
end
View
@@ -1,2 +1,5 @@
class Media < ActiveRecord::Base
+ belongs_to :items
+ has_many :checkouts
+ has_many :downloads
end
View
@@ -1,2 +1,4 @@
class User < ActiveRecord::Base
+ has_many :checkouts
+ has_many :downloads
end
@@ -1,9 +1,11 @@
class AddKeysToMedia < ActiveRecord::Migration
def self.up
add_column :medias, :item_id, :integer
+ add_index :medias, :item_id
end
def self.down
remove_column :medias, :item_id
+ remove_index :medias, :item_id
end
end
@@ -2,10 +2,14 @@ class AddKeysToCheckout < ActiveRecord::Migration
def self.up
add_column :checkouts, :user_id, :integer
add_column :checkouts, :media_id, :integer
+ add_index :checkouts, :user_id
+ add_index :checkouts, :media_id
end
def self.down
remove_column :checkouts, :media_id
remove_column :checkouts, :user_id
+ remove_index :checkouts, :user_id
+ remove_index :checkouts, :media_id
end
end
@@ -2,10 +2,14 @@ class AddKeysToDownloads < ActiveRecord::Migration
def self.up
add_column :downloads, :user_id, :integer
add_column :downloads, :media_id, :integer
+ add_index :downloads, :user_id
+ add_index :downloads, :media_id
end
def self.down
remove_column :downloads, :media_id
remove_column :downloads, :user_id
+ remove_index :downloads, :user_id
+ remove_index :downloads, :media_id
end
end

0 comments on commit c1d3286

Please sign in to comment.