# -*- encoding : utf-8 -*-
class Album < ActiveRecord::Base
  validates :name, :presence => true #, :uniqueness => true
  belongs_to :album_folder
  
  has_many :image_files
  
  
  def update_image_count 
    puts "update"
    self.images_count_cache = self.image_files.count
    
    self.album_folder.save if self.album_folder
    
    self.save
    
    
    
  end
  
  def self.update_image_counts
    Album.all.each do |album|
      album.update_image_count
    end
    
  end
  
end
