activerecord 1.14.2 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,9 +1,18 @@
1
- *1.14.2* (April 9th, 2005)
1
+ *1.14.3* (June 27th, 2006)
2
+
3
+ * Properly quote index names in migrations (closes #4764) [John Long]
4
+
5
+ * Ensure that Associations#include_eager_conditions? checks both scoped and explicit conditions [Rick]
6
+
7
+ * Associations#select_limited_ids_list adds the ORDER BY columns to the SELECT DISTINCT List for postgresql. [Rick]
8
+
9
+
10
+ *1.14.2* (April 9th, 2006)
2
11
 
3
12
  * Fixed calculations for the Oracle Adapter (closes #4626) [Michael Schoen]
4
13
 
5
14
 
6
- *1.14.1* (April 6th, 2005)
15
+ *1.14.1* (April 6th, 2006)
7
16
 
8
17
  * Fix type_name_with_module to handle type names that begin with '::'. Closes #4614. [Nicholas Seckar]
9
18
 
@@ -58,7 +67,7 @@
58
67
  * Fixed broken OCIAdapter #4457 [schoenm@earthlink.net]
59
68
 
60
69
 
61
- *1.14.0* (March 27th, 2005)
70
+ *1.14.0* (March 27th, 2006)
62
71
 
63
72
  * Replace 'rescue Object' with a finer grained rescue. Closes #4431. [Nicholas Seckar]
64
73
 
@@ -478,6 +487,7 @@
478
487
 
479
488
  * Fixed :through relations when using STI inherited classes would use the inherited class's name as foreign key on the join model [Tobias Luetke]
480
489
 
490
+
481
491
  *1.13.2* (December 13th, 2005)
482
492
 
483
493
  * Become part of Rails 1.0
data/Rakefile CHANGED
@@ -173,8 +173,8 @@ desc "Publish the release files to RubyForge."
173
173
  task :release => [ :package ] do
174
174
  `rubyforge login`
175
175
 
176
- for ext in %w( gem )
177
- release_command = "rubyforge add_release activerecord activerecord 'REL #{PKG_VERSION}' pkg/activerecord-#{PKG_VERSION}.#{ext}"
176
+ for ext in %w( gem tgz zip )
177
+ release_command = "rubyforge add_release #{PKG_NAME} #{PKG_NAME} 'REL #{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}"
178
178
  puts release_command
179
179
  system(release_command)
180
180
  end
@@ -1163,18 +1163,19 @@ module ActiveRecord
1163
1163
  end
1164
1164
 
1165
1165
  def select_limited_ids_list(options, join_dependency)
1166
- connection.select_values(
1166
+ connection.select_all(
1167
1167
  construct_finder_sql_for_association_limiting(options, join_dependency),
1168
1168
  "#{name} Load IDs For Limited Eager Loading"
1169
- ).collect { |id| connection.quote(id) }.join(", ")
1169
+ ).collect { |row| connection.quote(row[primary_key]) }.join(", ")
1170
1170
  end
1171
1171
 
1172
1172
  def construct_finder_sql_for_association_limiting(options, join_dependency)
1173
1173
  scope = scope(:find)
1174
- #sql = "SELECT DISTINCT #{table_name}.#{primary_key} FROM #{table_name} "
1175
1174
  sql = "SELECT "
1176
1175
  sql << "DISTINCT #{table_name}." if include_eager_conditions?(options) || include_eager_order?(options)
1177
- sql << "#{primary_key} FROM #{table_name} "
1176
+ sql << primary_key
1177
+ sql << ", #{options[:order].split(',').collect { |s| s.split.first } * ', '}" if options[:order] && (include_eager_conditions?(options) || include_eager_order?(options))
1178
+ sql << " FROM #{table_name} "
1178
1179
 
1179
1180
  if include_eager_conditions?(options) || include_eager_order?(options)
1180
1181
  sql << join_dependency.join_associations.collect{|join| join.association_join }.join
@@ -1186,16 +1187,24 @@ module ActiveRecord
1186
1187
  add_limit!(sql, options, scope)
1187
1188
  return sanitize_sql(sql)
1188
1189
  end
1189
-
1190
+
1191
+ # Checks if the conditions reference a table other than the current model table
1190
1192
  def include_eager_conditions?(options)
1191
- conditions = scope(:find, :conditions) || options[:conditions]
1192
- return false unless conditions
1193
- conditions = conditions.first if conditions.is_a?(Array)
1194
- conditions.scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name|
1193
+ # look in both sets of conditions
1194
+ conditions = [scope(:find, :conditions), options[:conditions]].inject([]) do |all, cond|
1195
+ case cond
1196
+ when nil then all
1197
+ when Array then all << cond.first
1198
+ else all << cond
1199
+ end
1200
+ end
1201
+ return false unless conditions.any?
1202
+ conditions.join(' ').scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name|
1195
1203
  condition_table_name != table_name
1196
1204
  end
1197
1205
  end
1198
1206
 
1207
+ # Checks if the query order references a table other than the current model's table.
1199
1208
  def include_eager_order?(options)
1200
1209
  order = options[:order]
1201
1210
  return false unless order
@@ -42,26 +42,29 @@ module ActiveRecord
42
42
  #
43
43
  # Note: Person.count(:all) will not work because it will use :all as the condition. Use Person.count instead.
44
44
  def count(*args)
45
- options = {}
46
-
47
- #For backwards compatibility, we need to handle both count(conditions=nil, joins=nil) or count(options={}).
48
- if args.size >= 0 and args.size <= 2
45
+ options = {}
46
+ column_name = :all
47
+ # For backwards compatibility, we need to handle both count(conditions=nil, joins=nil) or count(options={}) or count(column_name=:all, options={}).
48
+ if args.size >= 0 && args.size <= 2
49
49
  if args.first.is_a?(Hash)
50
- options = args.first
51
- #should we verify the options hash???
50
+ options = args.first
52
51
  elsif args[1].is_a?(Hash)
52
+ options = args[1]
53
53
  column_name = args.first
54
- options = args[1]
55
54
  else
56
- # Handle legacy paramter options: def count(conditions=nil, joins=nil)
55
+ # Handle legacy paramter options: def count(conditions=nil, joins=nil)
57
56
  options.merge!(:conditions => args[0]) if args.length > 0
58
- options.merge!(:joins => args[1]) if args.length > 1
57
+ options.merge!(:joins => args[1]) if args.length > 1
59
58
  end
60
59
  else
61
60
  raise(ArgumentError, "Unexpected parameters passed to count(*args): expected either count(conditions=nil, joins=nil) or count(options={})")
62
61
  end
63
62
 
64
- (scope(:find, :include) || options[:include]) ? count_with_associations(options) : calculate(:count, :all, options)
63
+ if options[:include] || scope(:find, :include)
64
+ count_with_associations(options)
65
+ else
66
+ calculate(:count, column_name, options)
67
+ end
65
68
  end
66
69
 
67
70
  # Calculates average value on a given column. The value is returned as a float. See #calculate for examples with options.
@@ -119,7 +119,7 @@ module ActiveRecord
119
119
  # Adds a new column to the named table.
120
120
  # See TableDefinition#column for details of the options you can use.
121
121
  def add_column(table_name, column_name, type, options = {})
122
- add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}"
122
+ add_column_sql = "ALTER TABLE #{table_name} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit])}"
123
123
  add_column_options!(add_column_sql, options)
124
124
  execute(add_column_sql)
125
125
  end
@@ -128,7 +128,7 @@ module ActiveRecord
128
128
  # ===== Examples
129
129
  # remove_column(:suppliers, :qualification)
130
130
  def remove_column(table_name, column_name)
131
- execute "ALTER TABLE #{table_name} DROP #{column_name}"
131
+ execute "ALTER TABLE #{table_name} DROP #{quote_column_name(column_name)}"
132
132
  end
133
133
 
134
134
  # Changes the column's definition according to the new options.
@@ -184,7 +184,8 @@ module ActiveRecord
184
184
  # generates
185
185
  # CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)
186
186
  def add_index(table_name, column_name, options = {})
187
- index_name = "#{table_name}_#{Array(column_name).first}_index"
187
+ column_names = Array(column_name)
188
+ index_name = index_name(table_name, :column => column_names.first)
188
189
 
189
190
  if Hash === options # legacy support, since this param was a string
190
191
  index_type = options[:unique] ? "UNIQUE" : ""
@@ -192,8 +193,8 @@ module ActiveRecord
192
193
  else
193
194
  index_type = options
194
195
  end
195
-
196
- execute "CREATE #{index_type} INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})"
196
+ quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
197
+ execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{table_name} (#{quoted_column_names})"
197
198
  end
198
199
 
199
200
  # Remove the given index from the table.
@@ -209,7 +210,7 @@ module ActiveRecord
209
210
  # add_index :accounts, [:username, :password]
210
211
  # remove_index :accounts, :username
211
212
  def remove_index(table_name, options = {})
212
- execute "DROP INDEX #{index_name(table_name, options)} ON #{table_name}"
213
+ execute "DROP INDEX #{quote_column_name(index_name(table_name, options))} ON #{table_name}"
213
214
  end
214
215
 
215
216
  def index_name(table_name, options) #:nodoc:
@@ -18,7 +18,6 @@ module ActiveRecord
18
18
  end
19
19
  end
20
20
 
21
-
22
21
  config = config.symbolize_keys
23
22
  host = config[:host]
24
23
  port = config[:port]
@@ -337,8 +337,7 @@ module ActiveRecord
337
337
 
338
338
  def remove_index(table_name, options) #:nodoc:
339
339
  execute "DROP INDEX #{index_name(table_name, options)}"
340
- end
341
-
340
+ end
342
341
 
343
342
  private
344
343
  BYTEA_COLUMN_TYPE_OID = 17
@@ -213,13 +213,7 @@ module ActiveRecord
213
213
  end
214
214
 
215
215
  def remove_index(table_name, options={}) #:nodoc:
216
- if Hash === options
217
- index_name = options[:name]
218
- else
219
- index_name = "#{table_name}_#{options}_index"
220
- end
221
-
222
- execute "DROP INDEX #{index_name}"
216
+ execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}"
223
217
  end
224
218
 
225
219
  def rename_table(name, new_name)
@@ -2,7 +2,7 @@ module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 14
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -179,6 +179,42 @@ class EagerAssociationTest < Test::Unit::TestCase
179
179
  assert_equal count, posts.size
180
180
  end
181
181
 
182
+ def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
183
+ posts = nil
184
+ Post.with_scope(:find => {
185
+ :include => :comments,
186
+ :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'"
187
+ }) do
188
+ posts = authors(:david).posts.find(:all, :limit => 2)
189
+ assert_equal 2, posts.size
190
+ end
191
+
192
+ Post.with_scope(:find => {
193
+ :include => [ :comments, :author ],
194
+ :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')"
195
+ }) do
196
+ count = Post.count(:limit => 2)
197
+ assert_equal count, posts.size
198
+ end
199
+ end
200
+
201
+ def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the_eagers
202
+ Post.with_scope(:find => { :conditions => "1=1" }) do
203
+ posts = authors(:david).posts.find(:all,
204
+ :include => :comments,
205
+ :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
206
+ :limit => 2
207
+ )
208
+ assert_equal 2, posts.size
209
+
210
+ count = Post.count(
211
+ :include => [ :comments, :author ],
212
+ :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')",
213
+ :limit => 2
214
+ )
215
+ assert_equal count, posts.size
216
+ end
217
+ end
182
218
  def test_eager_association_loading_with_habtm
183
219
  posts = Post.find(:all, :include => :categories, :order => "posts.id")
184
220
  assert_equal 2, posts[0].categories.size
@@ -34,6 +34,7 @@ if ActiveRecord::Base.connection.supports_migrations?
34
34
  Reminder.reset_column_information
35
35
 
36
36
  Person.connection.remove_column("people", "last_name") rescue nil
37
+ Person.connection.remove_column("people", "key") rescue nil
37
38
  Person.connection.remove_column("people", "bio") rescue nil
38
39
  Person.connection.remove_column("people", "age") rescue nil
39
40
  Person.connection.remove_column("people", "height") rescue nil
@@ -47,12 +48,17 @@ if ActiveRecord::Base.connection.supports_migrations?
47
48
  def test_add_index
48
49
  Person.connection.add_column "people", "last_name", :string
49
50
  Person.connection.add_column "people", "administrator", :boolean
51
+ Person.connection.add_column "people", "key", :string
50
52
 
51
53
  assert_nothing_raised { Person.connection.add_index("people", "last_name") }
52
54
  assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
53
55
 
54
56
  assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
55
57
  assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
58
+
59
+ # quoting
60
+ assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key", :unique => true) }
61
+ assert_nothing_raised { Person.connection.remove_index("people", :name => "key") }
56
62
 
57
63
  # Sybase adapter does not support indexes on :boolean columns
58
64
  unless current_adapter?(:SybaseAdapter)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.14.2
7
- date: 2006-04-09 00:00:00 -05:00
6
+ version: 1.14.3
7
+ date: 2006-06-27 00:00:00 -05:00
8
8
  summary: Implements the ActiveRecord pattern for ORM.
9
9
  require_paths:
10
10
  - lib