From eba79f257fc880e4ed01e4f209b302d051573bf3 Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Sun, 11 Mar 2012 18:04:09 -0400
Subject: [PATCH] Fix issue #199.

Return zero results more reliably. Formerly an exception was raised when
the table didn't have an 'id' column.
---
 lib/geocoder/stores/active_record.rb | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb
index 6272551f..40974b51 100644
--- a/lib/geocoder/stores/active_record.rb
+++ b/lib/geocoder/stores/active_record.rb
@@ -36,7 +36,7 @@ module Geocoder::Store
           if latitude and longitude
             near_scope_options(latitude, longitude, *args)
           else
-            where(:id => false) # no results if no lat/lon given
+            where(false_condition) # no results if no lat/lon given
           end
         }
 
@@ -244,6 +244,13 @@ module Geocoder::Store
       def using_sqlite?
         connection.adapter_name.match /sqlite/i
       end
+
+      ##
+      # Value which can be passed to where() to produce no results.
+      #
+      def false_condition
+        using_sqlite? ? 0 : "false"
+      end
     end
 
     ##
-- 
GitLab