From 2a260abf05ba0cff3ef75fa3c76af72190b5d613 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 3 Dec 2013 12:56:57 +0000 Subject: [PATCH] Fix Postgres problem with PlantParts#crops 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. --- app/models/plant_part.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/plant_part.rb b/app/models/plant_part.rb index cf085d459..e67e8c59b 100644 --- a/app/models/plant_part.rb +++ b/app/models/plant_part.rb @@ -11,4 +11,8 @@ class PlantPart < ActiveRecord::Base return name end + def crops + return super.reorder('name') + end + end