Title: [565] trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb: Hopefully make the monkeypatching work better
Revision
565
Author
olabini
Date
2007-05-09 16:33:05 -0400 (Wed, 09 May 2007)

Log Message

Hopefully make the monkeypatching work better

Modified Paths


Diff

Modified: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb (564 => 565)


--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb	2007-05-09 20:32:40 UTC (rev 564)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb	2007-05-09 20:33:05 UTC (rev 565)
@@ -2,6 +2,43 @@
 
 module JdbcSpec
   module Derby
+    def self.monkey_rails
+      unless @already_monkeyd
+        # Needed because Rails is broken wrt to quoting of 
+        # some values. Most databases are nice about it,
+        # but not Derby. The real issue is that you can't
+        # compare a CHAR value to a NUMBER column.
+        ::ActiveRecord::Associations::ClassMethods.module_eval do
+          private
+
+          def select_limited_ids_list(options, join_dependency)
+            connection.select_all(
+                                  construct_finder_sql_for_association_limiting(options, join_dependency),
+                                  "#{name} Load IDs For Limited Eager Loading"
+                                  ).collect { |row| quote_primary_key(row[primary_key]) }.join(", ")
+          end
+
+          def quote_primary_key(value)
+            if parent.respond_to? :quote_value
+              parent.quote_value(value, parent.columns_hash[parent.primary_key])
+            else
+              connection.quote(value)
+            end
+          end
+        end 
+
+        @already_monkeyd = true
+      end
+    end
+
+    def self.extended(*args)
+      monkey_rails
+    end
+
+    def self.included(*args)
+      monkey_rails
+    end
+    
     module Column
       def type_cast(value)
         return nil if value.nil? || value =~ /^\s*null\s*$/i
@@ -328,25 +365,3 @@
   end
 end
 
-# Needed because Rails is broken wrt to quoting of 
-# some values. Most databases are nice about it,
-# but not Derby. The real issue is that you can't
-# compare a CHAR value to a NUMBER column.
-module ActiveRecord::Associations::ClassMethods
-  private
-
-  def select_limited_ids_list(options, join_dependency)
-    connection.select_all(
-      construct_finder_sql_for_association_limiting(options, join_dependency),
-      "#{name} Load IDs For Limited Eager Loading"
-    ).collect { |row| quote_primary_key(row[primary_key]) }.join(", ")
-  end
-
-  def quote_primary_key(value)
-    if parent.respond_to? :quote_value
-      parent.quote_value(value, parent.columns_hash[parent.primary_key])
-    else
-      connection.quote(value)
-    end
-  end
-end 
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to