26 lines
709 B
Ruby
Executable File
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
|