class PArticle < ApplicationRecord belongs_to :p_grade belongs_to :p_product_ref has_one :p_product, through: :p_product_ref has_one :p_product_color, through: :p_product_ref has_one :s_brand, through: :p_product_ref has_many :p_article_serial_nums, dependent: :destroy # has_many :p_serial_num_values, through: :p_article_serial_nums accepts_nested_attributes_for :p_article_serial_nums validates_presence_of :p_product_ref # has_many :p_product_ref_specs, through: :p_product_ref # accepts_nested_attributes_for :p_product_ref_specs if PGrade::ACTIVATED acts_as_sorting :fields => { :id => {:name => "id", :reorder => true}, :p_product_ref_ref => {:name => "Code ref", :reorder => true}, :p_product_ref => {:name => "Désignation", :reorder => true}, :p_grade => {:name => "Grade", :reorder => true}, :color => {:name => "Couleur"}, :p_article_serial_nums => {:name => "N° identifiants"}, :actions => {:name => "Actions", :reorder => false}, } else acts_as_sorting :fields => { :id => {:name => "id", :reorder => true}, :p_product_ref_ref => {:name => "Code ref", :reorder => true}, :p_product_ref => {:name => "Désignation", :reorder => true}, :color => {:name => "Couleur"}, :p_article_serial_nums => {:name => "N° identifiants"}, :actions => {:name => "Actions", :reorder => false}, } end include PgSearch::Model pg_search_scope :global_search, associated_against: { p_product_ref: [:cc_name, :ref], s_brand: [ :code, :name ], p_product_color: [:name, :color], p_article_serial_nums: [:value] }, using: { tsearch: { prefix: true } } def member_label "#{p_product_ref.cc_name}" end end