lib/active_record/acts/category.rb
# Validator for parent_id association after creation and update of a category
Validator for parent_id association after creation and update of a category
Validator for parent_id association after creation and update of a category
def validate_foreign_key
          unless self.read_attribute(parent_id_column).nil?
            self.write_attribute(parent_id_column, 0) if self.read_attribute(parent_id_column) > 0 && !self.class.find(self.read_attribute(parent_id_column))
            self.write_attribute(parent_id_column, 0) if self.read_attribute(parent_id_column) > 0 && self.id == self.read_attribute(parent_id_column) unless self.id.blank?
            self.write_attribute(parent_id_column, 0) if self.read_attribute(parent_id_column) > 0 && self.descendants_ids.include?(self.read_attribute(parent_id_column))
          end
          rescue ActiveRecord::RecordNotFound
          self.write_attribute(parent_id_column, 0) 
        end
def validate_foreign_key unless self . read_attribute ( parent_id_column ) . nil? self . write_attribute ( parent_id_column , 0 ) if self . read_attribute ( parent_id_column ) > 0 && ! self . class . find ( self . read_attribute ( parent_id_column ) ) self . write_attribute ( parent_id_column , 0 ) if self . read_attribute ( parent_id_column ) > 0 && self . id == self . read_attribute ( parent_id_column ) unless self . id . blank? self . write_attribute ( parent_id_column , 0 ) if self . read_attribute ( parent_id_column ) > 0 && self . descendants_ids . include? ( self . read_attribute ( parent_id_column ) ) end rescue ActiveRecord :: RecordNotFound self . write_attribute ( parent_id_column , 0 ) end
Validator for parent_id association after creation and update of a category
Validator for parent_id association after creation and update of a category
# If there is a parent_id given # Parent_id must be a valid category ID # Parent must not be itself # Parent must not be a descendant of itself # Parent was not found