vita_app/app/models/product_collection_lang.rb
Nicolas Bally 1d3af87d4c initial
2016-04-28 10:07:08 +02:00

26 lines
709 B
Ruby
Executable File

class ProductCollectionLang < ActiveRecord::Base
belongs_to :product_collection
validates :name, :presence => true
validates :slug, :presence => true#, :uniqueness => {:scope => [:lang]}
attr_accessor :product_category_id
before_validation do
self.slug = self.name.to_slug
search_test = ProductCollectionLang.joins(:product_collection).where("lang = ?", self.lang).where("product_collections.product_category_id = ? and slug = ? ", self.product_category_id, self.slug)
search_test = search_test.where("product_collections.id != ?", self.id) if self.id
if search_test.first
#errors.add(:slug, 'est déjà utilisé')
end
end
end