class PProductAssembled < ApplicationRecord belongs_to :parent_product_ref, :class_name => "PProductRef" belongs_to :p_product_ref before_validation do if self.parent_product_ref_id == self.p_product_ref_id errors.add(:p_product_ref_id, 'ne peut pas ĂȘtre le produit parent') end end end