<commit_before>class PlantPart < ApplicationRecord
  extend FriendlyId
  friendly_id :name, use: %i(slugged finders)

  has_many :harvests
  has_many :crops, -> { uniq }, through: :harvests

  def to_s
    name
  end

  # Postgres complains if the ORDER BY clause of a SELECT DISTINCT query is
  # not precisely one of the SELECTed fields. The default sort order on
  # crops is lower(name), and Postgres is not smart enough to notice that it
  # can calculate this from fields which are selected. The solution is to
  # override PlantParts#crops to remove the ORDER BY clause, and replace it
  # with `ORDER BY name`. This is not perfect, because it means the crops
  # associated to plant parts will not be sorted in the same order as crops
  # on the rest of the site.
  def crops
    super.reorder('name')
  end
end<commit_msg>Plant parts model using distinct query<commit_after>class PlantPart < ApplicationRecord
  extend FriendlyId
  friendly_id :name, use: %i(slugged finders)

  has_many :harvests
  has_many :crops, -> { distinct }, through: :harvests

  def to_s
    name
  end
end
{'fraction_non_alphanumeric': 0.05952380952380952, 'fraction_numerical': 0.0, 'mean_word_length': 3.752173913043478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4591593', 'n_tokens_mistral': 332, 'n_tokens_neox': 322, 'n_words': 146}