summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/creation.rb2
-rw-r--r--db/migrate/20130706103848_add_creations_count_to_users.rb13
-rw-r--r--db/schema.rb3
3 files changed, 16 insertions, 2 deletions
diff --git a/app/models/creation.rb b/app/models/creation.rb
index 3cb64db2..6b8c3155 100644
--- a/app/models/creation.rb
+++ b/app/models/creation.rb
@@ -4,7 +4,7 @@ class Creation < ActiveRecord::Base
acts_as_commentable
validates :name, :presence => true
attr_accessible :user_id, :story, :name, :category_ids, :is_restricted, :watermark
- belongs_to :user
+ belongs_to :user, :counter_cache => true
has_and_belongs_to_many :categories, :join_table => 'creations_categories', :uniq => true, :autosave => true
has_many :photos, :dependent => :destroy, :order => :created_at
has_many :favorites, :dependent => :destroy
diff --git a/db/migrate/20130706103848_add_creations_count_to_users.rb b/db/migrate/20130706103848_add_creations_count_to_users.rb
new file mode 100644
index 00000000..e7f7b048
--- /dev/null
+++ b/db/migrate/20130706103848_add_creations_count_to_users.rb
@@ -0,0 +1,13 @@
+class AddCreationsCountToUsers < ActiveRecord::Migration
+ def up
+ add_column :users, :creations_count, :integer, :default => 0
+ User.reset_column_information
+ User.find_each do |user|
+ User.reset_counters user.id, :creations
+ end
+ end
+
+ def down
+ remove_column :users, :creations_count
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 12c9cdc9..cb643854 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130702213105) do
+ActiveRecord::Schema.define(:version => 20130706103848) do
create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
@@ -229,6 +229,7 @@ ActiveRecord::Schema.define(:version => 20130702213105) do
t.string "authentication_token"
t.string "invitation_token"
t.string "full_address"
+ t.integer "creations_count", :default => 0
end
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true