<commit_before>class Document < ActiveRecord::Base
  has_many :editions

  def self.published
    where %{
      EXISTS (
        SELECT 1 FROM editions AS published_editions
        WHERE published_editions.document_id = documents.id
        AND published_editions.state = 'published'
      )
    }
  end

  def published_edition
    editions.published.first
  end
end<commit_msg>Replace handcrafted sql with a defined association<commit_after>class Document < ActiveRecord::Base
  has_many :editions
  has_one :published_edition, class_name: 'Edition', conditions: { state: 'published' }

  def self.published
    joins(:published_edition)
  end
end
{'fraction_non_alphanumeric': 0.06912442396313365, 'fraction_numerical': 0.0015360983102918587, 'mean_word_length': 3.6906474820143886, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4402265', 'n_tokens_mistral': 195, 'n_tokens_neox': 186, 'n_words': 49}