ref: master
plugins/products/models/products_plugin/certifier.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
class ProductsPlugin::Certifier < ApplicationRecord self.table_name = :certifiers attr_accessible :name, :environment SEARCHABLE_FIELDS = { :name => {:label => _('Name'), :weight => 10}, :description => {:label => _('Description'), :weight => 3}, :link => {:label => _('Link'), :weight => 1}, } belongs_to :environment has_many :qualifier_certifiers, :dependent => :destroy has_many :qualifiers, :through => :qualifier_certifiers has_many :product_qualifiers has_many :products, :through => :product_qualifiers, :source => :product validates_presence_of :environment_id validates_presence_of :name def destroy product_qualifiers.each { |pq| pq.update! :certifier => nil } super end def link self[:link] || '' end def <=>(b) self.name.downcase.transliterate <=> b.name.downcase.transliterate end end |