aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/request_classification.rb16
-rw-r--r--db/migrate/20120910153022_create_request_classifications.rb14
2 files changed, 30 insertions, 0 deletions
diff --git a/app/models/request_classification.rb b/app/models/request_classification.rb
new file mode 100644
index 000000000..678b6cd16
--- /dev/null
+++ b/app/models/request_classification.rb
@@ -0,0 +1,16 @@
+class RequestClassification < ActiveRecord::Base
+ belongs_to :user
+
+ # return classification instances representing the top n
+ # users, with a 'cnt' attribute representing the number
+ # of classifications the user has made.
+ def RequestClassification.league_table(size, conditions=[])
+ find(:all, :select => 'user_id, count(*) as cnt',
+ :conditions => conditions,
+ :group => 'user_id',
+ :order => 'cnt desc',
+ :limit => size,
+ :include => :user)
+ end
+
+end \ No newline at end of file
diff --git a/db/migrate/20120910153022_create_request_classifications.rb b/db/migrate/20120910153022_create_request_classifications.rb
new file mode 100644
index 000000000..7c6270c9e
--- /dev/null
+++ b/db/migrate/20120910153022_create_request_classifications.rb
@@ -0,0 +1,14 @@
+class CreateRequestClassifications < ActiveRecord::Migration
+ def self.up
+ create_table :request_classifications do |t|
+ t.integer :user_id
+ t.integer :info_request_event_id
+ t.timestamps
+ end
+ add_index :request_classifications, :user_id
+ end
+
+ def self.down
+ drop_table :request_classifications
+ end
+end