# HG changeset patch # User Jittat Fakcharoenphol # Date 2010-02-16 17:51:02 # Node ID 5fffb74cc1829de93e83ef1685d9ae00aed0e6f5 # Parent 0b01fdb623a84f92220f470239cd0ab003dfabfe created join tables for contests and users and problems diff --git a/app/models/contest.rb b/app/models/contest.rb --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -1,2 +1,6 @@ class Contest < ActiveRecord::Base + + has_and_belongs_to_many :users + has_and_belongs_to_many :problems + end diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -1,6 +1,7 @@ class Problem < ActiveRecord::Base belongs_to :description + has_and_belongs_to_many :contests has_many :test_pairs, :dependent => :delete_all validates_presence_of :name diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,6 +21,8 @@ belongs_to :site belongs_to :country + has_and_belongs_to_many :contests + named_scope :activated_users, :conditions => {:activated => true} validates_presence_of :login diff --git a/db/migrate/20100216162324_create_contests_users_join_table.rb b/db/migrate/20100216162324_create_contests_users_join_table.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20100216162324_create_contests_users_join_table.rb @@ -0,0 +1,12 @@ +class CreateContestsUsersJoinTable < ActiveRecord::Migration + def self.up + create_table :contests_users, :id => false do |t| + t.integer :contest_id + t.integer :user_id + end + end + + def self.down + drop_table :contests_users + end +end diff --git a/db/migrate/20100216162940_create_contests_problems_join_table.rb b/db/migrate/20100216162940_create_contests_problems_join_table.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20100216162940_create_contests_problems_join_table.rb @@ -0,0 +1,12 @@ +class CreateContestsProblemsJoinTable < ActiveRecord::Migration + def self.up + create_table :contests_problems, :id => false do |t| + t.integer :contest_id + t.integer :problem_id + end + end + + def self.down + drop_table :contests_problems + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20100216105730) do +ActiveRecord::Schema.define(:version => 20100216162940) do create_table "announcements", :force => true do |t| t.string "author" @@ -46,6 +46,16 @@ t.datetime "updated_at" end + create_table "contests_problems", :id => false, :force => true do |t| + t.integer "contest_id" + t.integer "problem_id" + end + + create_table "contests_users", :id => false, :force => true do |t| + t.integer "contest_id" + t.integer "user_id" + end + create_table "countries", :force => true do |t| t.string "name" t.datetime "created_at"