diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb
index d31001afae672a54f38104ec60bbb0b80a6e26c5..6a7775b3f9d3fda65b1cb269563bddd1a7984ba9 100644
--- a/lib/diaspora/user/querying.rb
+++ b/lib/diaspora/user/querying.rb
@@ -55,7 +55,7 @@ module Diaspora
       # @param row The row to get the id from.
       # @return The id of the database row passed in.
       def id_for row
-        @@id_method_for_row ||= if Post.connection.class == ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
+        @@id_method_for_row ||= if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
                                   [:[], "id"]
                                 else
                                   :first