activerecord 3.0.7 → 3.0.8.rc1

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,3 +1,15 @@
1
+ *Rails 3.0.8 (unreleased)*
2
+
3
+ * Fix various problems with using :primary_key and :foreign_key options in conjunction with
4
+ :through associations. [Jon Leighton]
5
+
6
+ * Correctly handle inner joins on polymorphic relationships.
7
+
8
+ * Fixed infinity and negative infinity cases in PG date columns.
9
+
10
+ * Creating records with invalid associations via `create` or `save` will no
11
+ longer raise exceptions.
12
+
1
13
  *Rails 3.0.7 (April 18, 2011)*
2
14
 
3
15
  * Destroying records via nested attributes works independent of reject_if LH #6006 [Durran Jordan]
@@ -14,6 +26,10 @@
14
26
  cache type-casted values when the column returned from the db contains non-standard chars.
15
27
  [Jon Leighton]
16
28
 
29
+ * Fix performance bug with attribute accessors which only occurred on Ruby 1.8.7, and ensure we
30
+ cache type-casted values when the column returned from the db contains non-standard chars.
31
+ [Jon Leighton]
32
+
17
33
  * Fix a performance regression introduced here 86acbf1cc050c8fa8c74a10c735e467fb6fd7df8
18
34
  related to read_attribute method [Stian Grytøyr]
19
35
 
@@ -85,7 +85,7 @@ module ActiveRecord
85
85
  # only one level deep in the +associations+ argument, i.e. it's not passed
86
86
  # to the child associations when +associations+ is a Hash.
87
87
  def preload_associations(records, associations, preload_options={})
88
- records = Array.wrap(records).compact.uniq
88
+ records = Array.wrap(records).compact
89
89
  return if records.empty?
90
90
  case associations
91
91
  when Array then associations.each {|association| preload_associations(records, association, preload_options)}
@@ -97,6 +97,7 @@ module ActiveRecord
97
97
  reflection = reflections[parent]
98
98
  parents = records.sum { |record| Array.wrap(record.send(reflection.name)) }
99
99
  unless parents.empty?
100
+ parents = parents.uniq if reflection.macro == :belongs_to
100
101
  parents.first.class.preload_associations(parents, child)
101
102
  end
102
103
  end
@@ -2174,7 +2174,7 @@ module ActiveRecord
2174
2174
  end
2175
2175
 
2176
2176
  case source_reflection.macro
2177
- when :has_many
2177
+ when :has_many, :has_one
2178
2178
  if source_reflection.options[:as]
2179
2179
  first_key = "#{source_reflection.options[:as]}_id"
2180
2180
  second_key = options[:foreign_key] || primary_key
@@ -2199,7 +2199,7 @@ module ActiveRecord
2199
2199
 
2200
2200
  [
2201
2201
  [parent_table[jt_primary_key].eq(join_table[jt_foreign_key]), jt_as_extra, jt_source_extra, jt_sti_extra].reject{|x| x.blank? },
2202
- aliased_table[first_key].eq(join_table[second_key])
2202
+ [aliased_table[first_key].eq(join_table[second_key]), as_extra].reject{ |x| x.blank? }
2203
2203
  ]
2204
2204
  elsif reflection.options[:as]
2205
2205
  id_rel = aliased_table["#{reflection.options[:as]}_id"].eq(parent_table[parent.primary_key])
@@ -30,14 +30,14 @@ module ActiveRecord
30
30
  # Associate attributes pointing to owner, quoted.
31
31
  def construct_quoted_owner_attributes(reflection)
32
32
  if as = reflection.options[:as]
33
- { "#{as}_id" => owner_quoted_id,
33
+ { "#{as}_id" => @owner[reflection.active_record_primary_key],
34
34
  "#{as}_type" => reflection.klass.quote_value(
35
35
  @owner.class.base_class.name.to_s,
36
36
  reflection.klass.columns_hash["#{as}_type"]) }
37
37
  elsif reflection.macro == :belongs_to
38
38
  { reflection.klass.primary_key => @owner.class.quote_value(@owner[reflection.primary_key_name]) }
39
39
  else
40
- { reflection.primary_key_name => owner_quoted_id }
40
+ { reflection.primary_key_name => @owner[reflection.active_record_primary_key] }
41
41
  end
42
42
  end
43
43
 
@@ -53,7 +53,8 @@ module ActiveRecord
53
53
  def construct_joins(custom_joins = nil)
54
54
  polymorphic_join = nil
55
55
  if @reflection.source_reflection.macro == :belongs_to
56
- reflection_primary_key = @reflection.klass.primary_key
56
+ reflection_primary_key = @reflection.source_reflection.options[:primary_key] ||
57
+ @reflection.klass.primary_key
57
58
  source_primary_key = @reflection.source_reflection.primary_key_name
58
59
  if @reflection.options[:source_type]
59
60
  polymorphic_join = "AND %s.%s = %s" % [
@@ -63,7 +64,8 @@ module ActiveRecord
63
64
  end
64
65
  else
65
66
  reflection_primary_key = @reflection.source_reflection.primary_key_name
66
- source_primary_key = @reflection.through_reflection.klass.primary_key
67
+ source_primary_key = @reflection.source_reflection.options[:primary_key] ||
68
+ @reflection.through_reflection.klass.primary_key
67
69
  if @reflection.source_reflection.options[:as]
68
70
  polymorphic_join = "AND %s.%s = %s" % [
69
71
  @reflection.quoted_table_name, "#{@reflection.source_reflection.options[:as]}_type",
@@ -1,3 +1,8 @@
1
+ begin
2
+ require 'psych'
3
+ rescue LoadError
4
+ end
5
+
1
6
  require 'yaml'
2
7
  require 'set'
3
8
  require 'active_support/benchmarkable'
@@ -43,6 +43,16 @@ module ActiveRecord
43
43
  # :stopdoc:
44
44
  class << self
45
45
  attr_accessor :money_precision
46
+ def string_to_time(string)
47
+ return string unless String === string
48
+
49
+ case string
50
+ when 'infinity' then 1.0 / 0.0
51
+ when '-infinity' then -1.0 / 0.0
52
+ else
53
+ super
54
+ end
55
+ end
46
56
  end
47
57
  # :startdoc:
48
58
 
@@ -123,6 +133,14 @@ module ActiveRecord
123
133
  # Extracts the value from a PostgreSQL column default definition.
124
134
  def self.extract_value_from_default(default)
125
135
  case default
136
+ # This is a performance optimization for Ruby 1.9.2 in development.
137
+ # If the value is nil, we return nil straight away without checking
138
+ # the regular expressions. If we check each regular expression,
139
+ # Regexp#=== will call NilClass#to_str, which will trigger
140
+ # method_missing (defined by whiny nil in ActiveSupport) which
141
+ # makes this method very very slow.
142
+ when NilClass
143
+ nil
126
144
  # Numeric types
127
145
  when /\A\(?(-?\d+(\.\d*)?\)?)\z/
128
146
  $1
@@ -319,6 +337,9 @@ module ActiveRecord
319
337
 
320
338
  if value.kind_of?(String) && column.type == :binary
321
339
  "'#{escape_bytea(value)}'"
340
+ elsif Float === value && column.type == :datetime
341
+ return super unless value.infinite?
342
+ "'#{value.to_s.downcase}'"
322
343
  elsif value.kind_of?(String) && column.sql_type == 'xml'
323
344
  "xml '#{quote_string(value)}'"
324
345
  elsif value.kind_of?(Numeric) && column.sql_type == 'money'
@@ -975,7 +996,7 @@ module ActiveRecord
975
996
  def select(sql, name = nil)
976
997
  fields, rows = select_raw(sql, name)
977
998
  rows.map do |row|
978
- Hash[*fields.zip(row).flatten]
999
+ Hash[fields.zip(row)]
979
1000
  end
980
1001
  end
981
1002
 
@@ -1,4 +1,10 @@
1
1
  require 'erb'
2
+
3
+ begin
4
+ require 'psych'
5
+ rescue LoadError
6
+ end
7
+
2
8
  require 'yaml'
3
9
  require 'csv'
4
10
  require 'zlib'
@@ -1,5 +1,7 @@
1
1
  require 'active_support/core_ext/kernel/singleton_class'
2
2
  require 'active_support/core_ext/module/aliasing'
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'active_support/core_ext/class/attribute_accessors'
3
5
 
4
6
  module ActiveRecord
5
7
  # Exception that can be raised to stop migrations from going backwards.
@@ -36,7 +36,11 @@ module ActiveRecord
36
36
  # +save+ returns +false+. See ActiveRecord::Callbacks for further
37
37
  # details.
38
38
  def save(*)
39
- create_or_update
39
+ begin
40
+ create_or_update
41
+ rescue ActiveRecord::RecordInvalid
42
+ false
43
+ end
40
44
  end
41
45
 
42
46
  # Saves the model.
@@ -3,6 +3,13 @@ module ActiveRecord
3
3
  #
4
4
  # Defines some test assertions to test against SQL queries.
5
5
  class TestCase < ActiveSupport::TestCase #:nodoc:
6
+ # Backport skip to Ruby 1.8. test/unit doesn't support it, so just
7
+ # make it a noop.
8
+ unless instance_methods.map(&:to_s).include?("skip")
9
+ def skip(message)
10
+ end
11
+ end
12
+
6
13
  def assert_date_from_db(expected, actual, message = nil)
7
14
  # SybaseAdapter doesn't have a separate column type just for dates,
8
15
  # so the time is in the string and incorrectly formatted
@@ -2,8 +2,8 @@ module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 7
6
- PRE = nil
5
+ TINY = 8
6
+ PRE = "rc1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease:
4
+ hash: 15424055
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 7
10
- version: 3.0.7
9
+ - 8
10
+ - rc
11
+ - 1
12
+ version: 3.0.8.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - David Heinemeier Hansson
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-04-18 00:00:00 Z
20
+ date: 2011-05-25 00:00:00 Z
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  name: activesupport
@@ -25,12 +27,14 @@ dependencies:
25
27
  requirements:
26
28
  - - "="
27
29
  - !ruby/object:Gem::Version
28
- hash: 9
30
+ hash: 15424055
29
31
  segments:
30
32
  - 3
31
33
  - 0
32
- - 7
33
- version: 3.0.7
34
+ - 8
35
+ - rc
36
+ - 1
37
+ version: 3.0.8.rc1
34
38
  type: :runtime
35
39
  version_requirements: *id001
36
40
  - !ruby/object:Gem::Dependency
@@ -41,12 +45,14 @@ dependencies:
41
45
  requirements:
42
46
  - - "="
43
47
  - !ruby/object:Gem::Version
44
- hash: 9
48
+ hash: 15424055
45
49
  segments:
46
50
  - 3
47
51
  - 0
48
- - 7
49
- version: 3.0.7
52
+ - 8
53
+ - rc
54
+ - 1
55
+ version: 3.0.8.rc1
50
56
  type: :runtime
51
57
  version_requirements: *id002
52
58
  - !ruby/object:Gem::Dependency
@@ -57,12 +63,12 @@ dependencies:
57
63
  requirements:
58
64
  - - ~>
59
65
  - !ruby/object:Gem::Version
60
- hash: 11
66
+ hash: 27
61
67
  segments:
62
68
  - 2
63
69
  - 0
64
- - 2
65
- version: 2.0.2
70
+ - 10
71
+ version: 2.0.10
66
72
  type: :runtime
67
73
  version_requirements: *id003
68
74
  - !ruby/object:Gem::Dependency
@@ -206,16 +212,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
212
  required_rubygems_version: !ruby/object:Gem::Requirement
207
213
  none: false
208
214
  requirements:
209
- - - ">="
215
+ - - ">"
210
216
  - !ruby/object:Gem::Version
211
- hash: 3
217
+ hash: 25
212
218
  segments:
213
- - 0
214
- version: "0"
219
+ - 1
220
+ - 3
221
+ - 1
222
+ version: 1.3.1
215
223
  requirements: []
216
224
 
217
225
  rubyforge_project: activerecord
218
- rubygems_version: 1.7.2
226
+ rubygems_version: 1.8.2
219
227
  signing_key:
220
228
  specification_version: 3
221
229
  summary: Object-relational mapper framework (part of Rails).