class Image < ActiveRecord::Base
  belongs_to :items, :polymorphic => true
  # belongs_to :image, :polymorphic => true
  # belongs_to :auction, :polymorphic => true
  # belongs_to :item
  # belongs_to :auction_item
  # belongs_to :item
  # acts_as_list :scope => :auction_item_id
  # acts_as_list :scope => :item_id

  has_attached_file :image,
  :storage => :s3,
      :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
      :path => ":attachment/:id/:style.:extension"
  
  # has_attachment  :content_type => :image,
  #                 :size => 1.kilobyte..10.megabytes,
  #                 :thumbnails => { :thumb => [100, 100] },
  #                 :storage => :s3
  # 
  # validates_as_attachment
  
  # file_column :image, :magick => {
  #       :versions => { :thumb => {:crop => "1:1", :size => "150x150!", :name => "thumb"},
  #       :normal => {:size => "400x300>"}
  #       }
  #     }

  def self.order(ids)
    update_all(
      ['position = FIND_IN_SET(id, ?)', ids.join(',')],
      { :id => ids }
    )
  end

end