<commit_before>require_dependency 'article'

class Article

  has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_id IS NOT NULL']

  validate :body_change_with_comments

  def body_change_with_comments
    if body && body_changed? && !self.comments.empty?
      paragraphs_with_comments = self.comments.where("'paragraph_id' IS NOT NULL")
      errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty?
    end
  end
 
end
<commit_msg>comment_paragraph: fix article validation<commit_after>require_dependency 'article'

class Article

  has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_id IS NOT NULL']

  validate :body_change_with_comments

  def body_change_with_comments
    if body && body_changed? && !self.comments.empty?
      paragraphs_with_comments = self.comments.where("paragraph_id IS NOT NULL")
      errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty?
    end
  end
 
end

{'fraction_non_alphanumeric': 0.1086286594761171, 'fraction_numerical': 0.0, 'mean_word_length': 5.2451923076923075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6636933', 'n_tokens_mistral': 383, 'n_tokens_neox': 368, 'n_words': 109}