class ProductCollection < ActiveRecord::Base
  belongs_to :product_category
  
  has_many :product_collection_langs, :dependent => :destroy
    
  accepts_nested_attributes_for :product_collection_langs
  has_many :products, :dependent  => :nullify
  belongs_to :image_file
  
  before_validation do
    self.product_collection_langs.each do |product_collection_lang|
      product_collection_lang.product_category_id = self.product_category_id
      
    end
  end
  
  
  def lang(lang)
    self.product_collection_langs.find_by_lang(lang)
  end
  
end
