Commit 1f5009e6
Changed files (4)
app
models
views
app/models/favorite.rb
@@ -1,5 +1,5 @@
class Favorite < ActiveRecord::Base
belongs_to :user
- belongs_to :creation
+ belongs_to :creation, :counter_cache => true
attr_accessible :user_id, :creation_id
end
db/migrate/20130617041448_add_favorites_count_to_creations.rb
@@ -0,0 +1,13 @@
+class AddFavoritesCountToCreations < ActiveRecord::Migration
+ def up
+ add_column :creations, :favorites_count, :integer, :default => 0
+ Creation.reset_column_information
+ Creation.find_each do |creation|
+ Creation.reset_counters creation.id, :favorites
+ end
+ end
+
+ def down
+ remove_column :creations, :favorites_count
+ end
+end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130617040733) do
+ActiveRecord::Schema.define(:version => 20130617041448) do
create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
@@ -88,9 +88,10 @@ ActiveRecord::Schema.define(:version => 20130617040733) do
t.datetime "updated_at"
t.integer "user_id"
t.string "image"
- t.boolean "is_restricted", :default => false, :null => false
+ t.boolean "is_restricted", :default => false, :null => false
t.string "watermark"
- t.integer "photos_count", :default => 0
+ t.integer "photos_count", :default => 0
+ t.integer "favorites_count", :default => 0
end
add_index "creations", ["created_at"], :name => "index_creations_on_created_at"