quote_value and Rails 2.0

30 views
Skip to first unread message

Fabien Jakimowicz

unread,
Feb 6, 2007, 5:37:50 PM2/6/07
to Composite Keys for ActiveRecord
Hello,

i have noticed this message while using Composite Keys and Mongrel:

DEPRECATION WARNING: quote is deprecated and will be removed from
Rails 2.0 (use quote_value instead) See http://www.rubyonrails.org/deprecation
for details. (called from quoted_id at /usr/lib64/ruby/gems/1.8/gems/
composite_primary_keys-0.7.5/lib/composite_primary_keys/base.rb:63)


As it says, just change from quote to quote_value and error message
just vanished. If it can help :

--- lib/composite_primary_keys/base.rb~ 2007-02-01 02:03:25.672071000
+0100
+++ lib/composite_primary_keys/base.rb 2007-02-06 23:21:48.325009000
+0100
@@ -60,7 +60,7 @@
def quoted_id #:nodoc:
[self.class.primary_keys, ids].
transpose.
- map {|attr_name,id| quote(id,
column_for_attribute(attr_name))}.
+ map {|attr_name,id| quote_value(id,
column_for_attribute(attr_name))}.
to_composite_ids
end

Dr Nic

unread,
Feb 6, 2007, 11:29:58 PM2/6/07
to Composite Keys for ActiveRecord
Ok, added the change to svn, but I'm getting 24 test errors. Something
in latest rails might have changed, will need to investigate.

Nic

On Feb 7, 8:37 am, "Fabien Jakimowicz" <fab...@jakimowicz.com> wrote:
> Hello,
>
> i have noticed this message while using Composite Keys and Mongrel:
>
> DEPRECATION WARNING: quote is deprecated and will be removed from

> Rails 2.0 (use quote_value instead) Seehttp://www.rubyonrails.org/deprecation

darrin

unread,
Feb 8, 2007, 10:09:09 PM2/8/07
to Composite Keys for ActiveRecord
Here's a patch to get the tests passing again with the latest Rails
release, most errors were fixed by setting up the
ActiveRecord::Base.configurations

Index: trunk/test/find_test.rb
===================================================================
--- trunk/test/find_test.rb (revision 47)
+++ trunk/test/find_test.rb (working copy)
@@ -28,7 +28,7 @@

def test_find_first
testing_with do
- obj = @klass.ind(:first)
+ obj = @klass.find(:first)
assert obj
assert_equal @klass, obj.class
end
Index: trunk/test/connections/native_mysql/connection.rb
===================================================================
--- trunk/test/connections/native_mysql/connection.rb (revision 47)
+++ trunk/test/connections/native_mysql/connection.rb (working copy)
@@ -5,9 +5,12 @@

db1 = 'composite_primary_keys_unittest'

-ActiveRecord::Base.establish_connection(
+connection_options = {
:adapter => "mysql",
:username => "root",
:encoding => "utf8",
- :database => db1
-)
+ :database => db1
+}
+
+ActiveRecord::Base.configurations = { db1 => connection_options }
+ActiveRecord::Base.establish_connection(connection_options)
Index: trunk/test/pagination_test.rb
===================================================================
--- trunk/test/pagination_test.rb (revision 47)
+++ trunk/test/pagination_test.rb (working copy)
@@ -7,7 +7,9 @@
fixtures :reference_types, :reference_codes
include ActionController::Pagination
DEFAULT_PAGE_SIZE = 2
-
+
+ attr_accessor :params
+
CLASSES = {
:single => {
:class => ReferenceType,
Index: trunk/test/create_test.rb
===================================================================
--- trunk/test/create_test.rb (revision 47)
+++ trunk/test/create_test.rb (working copy)
@@ -2,7 +2,7 @@
require 'fixtures/reference_type'
require 'fixtures/reference_code'

-class DummyTest < Test::Unit::TestCase
+class CreateTest < Test::Unit::TestCase
fixtures :reference_types, :reference_codes

CLASSES = {
Index: trunk/lib/composite_primary_keys/calculations.rb
===================================================================
--- trunk/lib/composite_primary_keys/calculations.rb (revision 0)
+++ trunk/lib/composite_primary_keys/calculations.rb (revision 0)
@@ -0,0 +1,60 @@
+module CompositePrimaryKeys
+ module ActiveRecord
+ module Calculations
+ module ClassMethods
+ def construct_calculation_sql(operation, column_name,
options) #:nodoc:
+ operation = operation.to_s.downcase
+ options = options.symbolize_keys
+
+ scope = scope(:find)
+ merged_includes = merge_includes(scope ? scope[:include] :
[], options[:include])
+ aggregate_alias = column_alias_for(operation, column_name)
+ use_workaround = !connection.supports_count_distinct? &&
options[:distinct] && operation.to_s.downcase == 'count'
+ join_dependency = nil
+
+ if merged_includes.any? && operation.to_s.downcase ==
'count'
+ options[:distinct] = true
+ use_workaround = !connection.supports_count_distinct?
+ column_name = options[:select] || primary_key.map{ |part|
"#{table_name}.#{part}"}.join(',')
+ end
+
+ sql = "SELECT #{operation}(#{'DISTINCT ' if
options[:distinct]}#{column_name}) AS #{aggregate_alias}"
+
+ # A (slower) workaround if we're using a backend, like
sqlite, that doesn't support COUNT DISTINCT.
+ sql = "SELECT COUNT(*) AS #{aggregate_alias}" if
use_workaround
+
+ sql << ", #{options[:group_field]} AS
#{options[:group_alias]}" if options[:group]
+ sql << " FROM (SELECT DISTINCT #{column_name}" if
use_workaround
+ sql << " FROM #{table_name} "
+ if merged_includes.any?
+ join_dependency
= ::ActiveRecord::Associations::ClassMethods::JoinDependency.new(self,
merged_includes, options[:joins])
+ sql << join_dependency.join_associations.collect{|join|
join.association_join }.join
+ end
+ add_joins!(sql, options, scope)
+ add_conditions!(sql, options[:conditions], scope)
+ add_limited_ids_condition!(sql, options, join_dependency)
if join_dependency && !using_limitable_reflections?
(join_dependency.reflections) && ((scope && scope[:limit]) ||
options[:limit])
+
+ if options[:group]
+ group_key = Base.connection.adapter_name ==
'FrontBase' ? :group_alias : :group_field
+ sql << " GROUP BY #{options[group_key]} "
+ end
+
+ if options[:group] && options[:having]
+ # FrontBase requires identifiers in the HAVING clause and
chokes on function calls
+ if Base.connection.adapter_name == 'FrontBase'
+ options[:having].downcase!
+ options[:having].gsub!(/#{operation}\s*\
(\s*#{column_name}\s*\)/, aggregate_alias)
+ end
+
+ sql << " HAVING #{options[:having]} "
+ end
+
+ sql << " ORDER BY #{options[:order]} " if
options[:order]
+ add_limit!(sql, options, scope)
+ sql << ')' if use_workaround
+ sql
+ end
+ end
+ end
+ end
+end
Index: trunk/lib/composite_primary_keys/base.rb
===================================================================
--- trunk/lib/composite_primary_keys/base.rb (revision 47)
+++ trunk/lib/composite_primary_keys/base.rb (working copy)
@@ -22,9 +22,10 @@
self.primary_keys = keys.to_composite_keys

class_eval <<-EOV
- extend
CompositePrimaryKeys::ActiveRecord::Base::CompositeClassMethods
+ extend
CompositePrimaryKeys::ActiveRecord::Base::CompositeClassMethods
include
CompositePrimaryKeys::ActiveRecord::Base::CompositeInstanceMethods
include CompositePrimaryKeys::ActiveRecord::Associations
+ extend
CompositePrimaryKeys::ActiveRecord::Calculations::ClassMethods
EOV
end

@@ -267,6 +268,9 @@
ids = ids.first.split(ID_SET_SEP).map {|id_set|
id_set.split(ID_SEP).to_composite_ids}
# find '2,1;7,3' -> ids = [['2','1'],['7','3']], inner
[] are CompositeIds
end
+
+ ids.compact! #reload defaults options to nil which find
passes on here
+
ids = [ids.to_composite_ids] if not ids.first.kind_of?
(Array)
ids.each do |id_set|
unless id_set.is_a?(Array)
Index: trunk/lib/composite_primary_keys.rb
===================================================================
--- trunk/lib/composite_primary_keys.rb (revision 47)
+++ trunk/lib/composite_primary_keys.rb (working copy)
@@ -39,6 +39,7 @@
require 'composite_primary_keys/associations'
require 'composite_primary_keys/reflection'
require 'composite_primary_keys/base'
+require 'composite_primary_keys/calculations'

ActiveRecord::Base.class_eval do
include CompositePrimaryKeys::ActiveRecord::Base

darrin

unread,
Feb 8, 2007, 10:15:14 PM2/8/07
to Composite Keys for ActiveRecord
Here's the file, didn't realize it was going to wrap all the lines

http://groups.google.com/group/compositekeys/web/revision_47_patch.txt

On Feb 8, 9:09 pm, "darrin" <darrin.ho...@gmail.com> wrote:
> Here's a patch to get the tests passing again with the latest Rails
> release, most errors were fixed by setting up the
> ActiveRecord::Base.configurations
>

Lori M Olson

unread,
Mar 13, 2007, 1:12:34 PM3/13/07
to Composite Keys for ActiveRecord
Is this likely to be made available in a new release any time soon?

Regards, Lori

Reply all
Reply to author
Forward
0 new messages