Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

setup relations in models + indexes on foreign keys

  • Loading branch information...
commit c1d3286fba8cc4d2c8f246d8960a582ba49a6313 1 parent e23ec11
@jsjohnst authored
View
2  app/models/checkout.rb
@@ -1,2 +1,4 @@
class Checkout < ActiveRecord::Base
+ belongs_to :users
+ belongs_to :medias
end
View
2  app/models/downloads.rb
@@ -1,2 +1,4 @@
class Downloads < ActiveRecord::Base
+ belongs_to :users
+ belongs_to :medias
end
View
1  app/models/item.rb
@@ -1,2 +1,3 @@
class Item < ActiveRecord::Base
+ has_many :medias
end
View
3  app/models/media.rb
@@ -1,2 +1,5 @@
class Media < ActiveRecord::Base
+ belongs_to :items
+ has_many :checkouts
+ has_many :downloads
end
View
2  app/models/user.rb
@@ -1,2 +1,4 @@
class User < ActiveRecord::Base
+ has_many :checkouts
+ has_many :downloads
end
View
2  db/migrate/20091221013559_add_keys_to_media.rb
@@ -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
View
4 db/migrate/20091221013631_add_keys_to_checkout.rb
@@ -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
View
4 db/migrate/20091221013657_add_keys_to_downloads.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.