class Artwork < ActiveRecord::Base
  belongs_to :portfolio
  
  
  belongs_to :artwork_image
  has_many :artwork_images, :dependent => :destroy
  
  before_validation do 
    self.position = self.position || 1
		
    
  end
  
  after_create do 
    self.portfolio.artworks.where("id NOT IN (?)", self.id).each do |artwork|
      artwork.position = artwork.position + 1
      artwork.save
    end
  end
  
end
