activerecord 3.0.0.rc2 → 3.0.0

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,4 @@
1
- *Rails 3.0.0 [release candidate 2] (August 23rd, 2010)*
2
-
3
- * No material changes (see http://github.com/rails/rails/compare/v3.0.0_RC...v3.0.0_RC2 for gory details)
4
-
5
-
6
- *Rails 3.0.0 [release candidate] (July 26th, 2010)*
1
+ *Rails 3.0.0 (August 29, 2010)*
7
2
 
8
3
  * Changed update_attribute to not run callbacks and update the record directly in the database [Neeraj Singh]
9
4
 
@@ -15,9 +10,6 @@
15
10
 
16
11
  * PostgreSQL: ensure the database time zone matches Ruby's time zone #4895 [Aaron Patterson]
17
12
 
18
-
19
- *Rails 3.0.0 [beta 4] (June 8th, 2010)*
20
-
21
13
  * Fixed that ActiveRecord::Base.compute_type would swallow NoMethodError #4751 [Andrew Bloomgarden, Andrew White]
22
14
 
23
15
  * Add index length support for MySQL. #1852 [Emili Parreno, Pratik Naik]
@@ -42,9 +34,6 @@
42
34
 
43
35
  * Observers can prevent records from saving by returning false, just like before_save and friends. #4087 [Mislav Marohnić]
44
36
 
45
-
46
- *Rails 3.0.0 [beta 3] (April 13th, 2010)*
47
-
48
37
  * Add Relation extensions. [Pratik Naik]
49
38
 
50
39
  users = User.where(:admin => true).extending(User::AdminPowers)
@@ -59,9 +48,6 @@
59
48
 
60
49
  * Silenced "SHOW FIELDS" and "SET SQL_AUTO_IS_NULL=0" statements from the MySQL driver to improve log signal to noise ration in development [DHH]
61
50
 
62
-
63
- *Rails 3.0.0 [Beta 1] (February 4th, 2010)*
64
-
65
51
  * PostgreSQLAdapter: set time_zone to UTC when Base.default_timezone == :utc so that Postgres doesn't incorrectly offset-adjust values inserted into TIMESTAMP WITH TIME ZONE columns. #3777 [Jack Christensen]
66
52
 
67
53
  * Allow relations to be used as scope.
@@ -2044,7 +2030,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
2044
2030
  end
2045
2031
  end
2046
2032
 
2047
- * Fixed that schema changes while the database was open would break any connections to a SQLite database (now we reconnect if that error is throw) [David Heinemeier Hansson]
2033
+ * Fixed that schema changes while the database was open would break any connections to an SQLite database (now we reconnect if that error is throw) [David Heinemeier Hansson]
2048
2034
 
2049
2035
  * Don't classify the has_one class when eager loading, it is already singular. Add tests. (closes #4117) [Jonathan Viney]
2050
2036
 
@@ -3559,7 +3545,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
3559
3545
  end
3560
3546
  end
3561
3547
 
3562
- * Fixed that schema changes while the database was open would break any connections to a SQLite database (now we reconnect if that error is throw) [David Heinemeier Hansson]
3548
+ * Fixed that schema changes while the database was open would break any connections to an SQLite database (now we reconnect if that error is throw) [David Heinemeier Hansson]
3563
3549
 
3564
3550
  * Don't classify the has_one class when eager loading, it is already singular. Add tests. (closes #4117) [Jonathan Viney]
3565
3551
 
@@ -5223,7 +5209,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
5223
5209
  NOTE: The agreement is considered valid if it's set to the string "1". This makes it easy to relate it to an HTML checkbox.
5224
5210
 
5225
5211
 
5226
- * Added validation macros to make the stackable just like the lifecycle callbacks. Examples:
5212
+ * Added validation macros to make the stackable just like the life cycle callbacks. Examples:
5227
5213
 
5228
5214
  class Person < ActiveRecord::Base
5229
5215
  validate { |record| record.errors.add("name", "too short") unless name.size > 10 }
@@ -70,7 +70,7 @@ A short rundown of some of the major features:
70
70
  {Learn more}[link:classes/ActiveRecord/Validations.html]
71
71
 
72
72
 
73
- * Callbacks available for the entire lifecycle (instantiation, saving, destroying, validating, etc.)
73
+ * Callbacks available for the entire life cycle (instantiation, saving, destroying, validating, etc.)
74
74
 
75
75
  class Person < ActiveRecord::Base
76
76
  before_destroy :invalidate_payment_plan
@@ -340,7 +340,7 @@ module ActiveRecord
340
340
  #
341
341
  # === Association callbacks
342
342
  #
343
- # Similar to the normal callbacks that hook into the lifecycle of an Active Record object,
343
+ # Similar to the normal callbacks that hook into the life cycle of an Active Record object,
344
344
  # you can also define callbacks that get triggered when you add an object to or remove an
345
345
  # object from an association collection.
346
346
  #
@@ -26,7 +26,7 @@ module ActiveRecord
26
26
  def construct_find_options!(options)
27
27
  options[:joins] = Arel::SqlLiteral.new @join_sql
28
28
  options[:readonly] = finding_with_ambiguous_select?(options[:select] || @reflection.options[:select])
29
- options[:select] ||= (@reflection.options[:select] || '*')
29
+ options[:select] ||= (@reflection.options[:select] || Arel::SqlLiteral.new('*'))
30
30
  end
31
31
 
32
32
  def count_records
@@ -32,7 +32,7 @@ module ActiveRecord #:nodoc:
32
32
  # Active Record objects. The mapping that binds a given Active Record class to a certain
33
33
  # database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.
34
34
  #
35
- # See the mapping rules in table_name and the full example in link:files/README.html for more insight.
35
+ # See the mapping rules in table_name and the full example in link:files/activerecord/README_rdoc.html for more insight.
36
36
  #
37
37
  # == Creation
38
38
  #
@@ -876,7 +876,12 @@ module ActiveRecord #:nodoc:
876
876
  # limit(10) # Fires "SELECT * FROM posts LIMIT 10"
877
877
  # }
878
878
  #
879
- def unscoped
879
+ # It is recommended to use block form of unscoped because chaining unscoped with <tt>named_scope</tt>
880
+ # does not work. Assuming that <tt>published</tt> is a <tt>named_scope</tt> following two statements are same.
881
+ #
882
+ # Post.unscoped.published
883
+ # Post.published
884
+ def unscoped #:nodoc:
880
885
  block_given? ? relation.scoping { yield } : relation
881
886
  end
882
887
 
@@ -3,7 +3,7 @@ require 'active_support/core_ext/array/wrap'
3
3
  module ActiveRecord
4
4
  # = Active Record Callbacks
5
5
  #
6
- # Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic
6
+ # Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic
7
7
  # before or after an alteration of the object state. This can be used to make sure that associated and
8
8
  # dependent objects are deleted when +destroy+ is called (by overwriting +before_destroy+) or to massage attributes
9
9
  # before they're validated (by overwriting +before_validation+). As an example of the callbacks initiated, consider
@@ -26,7 +26,7 @@ module ActiveRecord
26
26
  # <tt>after_rollback</tt>.
27
27
  #
28
28
  # That's a total of ten callbacks, which gives you immense power to react and prepare for each state in the
29
- # Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar,
29
+ # Active Record life cycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar,
30
30
  # except that each <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback.
31
31
  #
32
32
  # Examples:
@@ -3,7 +3,7 @@ require 'active_support/core_ext/class/attribute'
3
3
  module ActiveRecord
4
4
  # = Active Record Observer
5
5
  #
6
- # Observer classes respond to lifecycle callbacks to implement trigger-like
6
+ # Observer classes respond to life cycle callbacks to implement trigger-like
7
7
  # behavior outside the original class. This is a great way to reduce the
8
8
  # clutter that normally comes when the model class is burdened with
9
9
  # functionality that doesn't pertain to the core responsibility of the
@@ -208,24 +208,37 @@ module ActiveRecord
208
208
  # If an attribute name is passed, that attribute is updated along with
209
209
  # updated_at/on attributes.
210
210
  #
211
- # Examples:
212
- #
213
211
  # product.touch # updates updated_at/on
214
212
  # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on
213
+ #
214
+ # If used along with +belongs_to+ then +touch+ will invoke +touch+ method on associated object.
215
+ #
216
+ # class Brake < ActiveRecord::Base
217
+ # belongs_to :car, :touch => true
218
+ # end
219
+ #
220
+ # class Car < ActiveRecord::Base
221
+ # belongs_to :corporation, :touch => true
222
+ # end
223
+ #
224
+ # # triggers @brake.car.touch and @brake.car.corporation.touch
225
+ # @brake.touch
215
226
  def touch(name = nil)
216
227
  attributes = timestamp_attributes_for_update_in_model
217
- attributes << name if name
228
+ unless attributes.blank?
229
+ attributes << name if name
218
230
 
219
- current_time = current_time_from_proper_timezone
220
- changes = {}
231
+ current_time = current_time_from_proper_timezone
232
+ changes = {}
221
233
 
222
- attributes.each do |column|
223
- changes[column.to_s] = write_attribute(column.to_s, current_time)
224
- end
234
+ attributes.each do |column|
235
+ changes[column.to_s] = write_attribute(column.to_s, current_time)
236
+ end
225
237
 
226
- @changed_attributes.except!(*changes.keys)
227
- primary_key = self.class.primary_key
228
- self.class.update_all(changes, { primary_key => self[primary_key] }) == 1
238
+ @changed_attributes.except!(*changes.keys)
239
+ primary_key = self.class.primary_key
240
+ self.class.update_all(changes, { primary_key => self[primary_key] }) == 1
241
+ end
229
242
  end
230
243
 
231
244
  private
@@ -61,12 +61,14 @@ namespace :db do
61
61
  @charset = ENV['CHARSET'] || 'utf8'
62
62
  @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
63
63
  creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
64
+ error_class = config['adapter'] =~ /mysql2/ ? Mysql2::Error : Mysql::Error
65
+ access_denied_error = 1045
64
66
  begin
65
67
  ActiveRecord::Base.establish_connection(config.merge('database' => nil))
66
68
  ActiveRecord::Base.connection.create_database(config['database'], creation_options)
67
69
  ActiveRecord::Base.establish_connection(config)
68
- rescue Mysql::Error => sqlerr
69
- if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR
70
+ rescue error_class => sqlerr
71
+ if sqlerr.errno == access_denied_error
70
72
  print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
71
73
  root_password = $stdin.gets.strip
72
74
  grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
@@ -7,18 +7,17 @@ module ActiveRecord
7
7
  #
8
8
  # * Count all: By not passing any parameters to count, it will return a count of all the rows for the model.
9
9
  # * Count using column: By passing a column name to count, it will return a count of all the
10
- # rows for the model with supplied column present
10
+ # rows for the model with supplied column present.
11
11
  # * Count using options will find the row count matched by the options used.
12
12
  #
13
13
  # The third approach, count using options, accepts an option hash as the only parameter. The options are:
14
14
  #
15
15
  # * <tt>:conditions</tt>: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ].
16
16
  # See conditions in the intro to ActiveRecord::Base.
17
- # * <tt>:joins</tt>: Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id" (rarely needed)
18
- # or named associations in the same form used for the <tt>:include</tt> option, which will
19
- # perform an INNER JOIN on the associated table(s).
20
- # If the value is a string, then the records will be returned read-only since they will have
21
- # attributes that do not correspond to the table's columns.
17
+ # * <tt>:joins</tt>: Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id"
18
+ # (rarely needed) or named associations in the same form used for the <tt>:include</tt> option, which will
19
+ # perform an INNER JOIN on the associated table(s). If the value is a string, then the records
20
+ # will be returned read-only since they will have attributes that do not correspond to the table's columns.
22
21
  # Pass <tt>:readonly => false</tt> to override.
23
22
  # * <tt>:include</tt>: Named associations that should be loaded alongside using LEFT OUTER JOINs.
24
23
  # The symbols named refer to already defined associations. When using named associations, count
@@ -27,8 +26,7 @@ module ActiveRecord
27
26
  # * <tt>:order</tt>: An SQL fragment like "created_at DESC, name" (really only used with GROUP BY calculations).
28
27
  # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
29
28
  # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you, for example,
30
- # want to do a join but not
31
- # include the joined columns.
29
+ # want to do a join but not include the joined columns.
32
30
  # * <tt>:distinct</tt>: Set this to true to make this a distinct calculation, such as
33
31
  # SELECT COUNT(DISTINCT posts.id) ...
34
32
  # * <tt>:from</tt> - By default, this is the table name of the class, but can be changed to an
@@ -96,14 +96,14 @@ module ActiveRecord
96
96
  end
97
97
 
98
98
  def reverse_order
99
- order_clause = arel.send(:order_clauses).join(', ')
99
+ order_clause = arel.order_clauses.join(', ')
100
100
  relation = except(:order)
101
101
 
102
- if order_clause.present?
103
- relation.order(reverse_sql_order(order_clause))
104
- else
105
- relation.order("#{@klass.table_name}.#{@klass.primary_key} DESC")
106
- end
102
+ order = order_clause.blank? ?
103
+ "#{@klass.table_name}.#{@klass.primary_key} DESC" :
104
+ reverse_sql_order(order_clause)
105
+
106
+ relation.order Arel::SqlLiteral.new order
107
107
  end
108
108
 
109
109
  def arel
@@ -188,7 +188,7 @@ module ActiveRecord
188
188
  association_joins << join if [Hash, Array, Symbol].include?(join.class) && !array_of_strings?(join)
189
189
  end
190
190
 
191
- stashed_association_joins = joins.select {|j| j.is_a?(ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation)}
191
+ stashed_association_joins = joins.grep(ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation)
192
192
 
193
193
  non_association_joins = (joins - association_joins - stashed_association_joins)
194
194
  custom_joins = custom_join_sql(*non_association_joins)
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
 
9
9
  ((Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS) - [:joins, :where]).each do |method|
10
10
  value = r.send(:"#{method}_values")
11
- if value.present?
11
+ unless value.empty?
12
12
  if method == :includes
13
13
  merged_relation = merged_relation.includes(value)
14
14
  else
@@ -61,7 +61,7 @@ module ActiveRecord
61
61
  end
62
62
 
63
63
  def should_record_timestamps?
64
- record_timestamps && !partial_updates? || changed?
64
+ record_timestamps && (!partial_updates? || changed?)
65
65
  end
66
66
 
67
67
  def timestamp_attributes_for_update_in_model
@@ -3,8 +3,7 @@ module ActiveRecord
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
5
  TINY = 0
6
- BUILD = "rc2"
7
6
 
8
- STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
9
8
  end
10
9
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- hash: 977940607
5
- prerelease: true
4
+ hash: 7
5
+ prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
- - rc2
11
- version: 3.0.0.rc2
10
+ version: 3.0.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - David Heinemeier Hansson
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-08-23 00:00:00 -05:00
18
+ date: 2010-08-29 00:00:00 -05:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -27,13 +26,12 @@ dependencies:
27
26
  requirements:
28
27
  - - "="
29
28
  - !ruby/object:Gem::Version
30
- hash: 977940607
29
+ hash: 7
31
30
  segments:
32
31
  - 3
33
32
  - 0
34
33
  - 0
35
- - rc2
36
- version: 3.0.0.rc2
34
+ version: 3.0.0
37
35
  type: :runtime
38
36
  version_requirements: *id001
39
37
  - !ruby/object:Gem::Dependency
@@ -44,13 +42,12 @@ dependencies:
44
42
  requirements:
45
43
  - - "="
46
44
  - !ruby/object:Gem::Version
47
- hash: 977940607
45
+ hash: 7
48
46
  segments:
49
47
  - 3
50
48
  - 0
51
49
  - 0
52
- - rc2
53
- version: 3.0.0.rc2
50
+ version: 3.0.0
54
51
  type: :runtime
55
52
  version_requirements: *id002
56
53
  - !ruby/object:Gem::Dependency
@@ -61,13 +58,12 @@ dependencies:
61
58
  requirements:
62
59
  - - ~>
63
60
  - !ruby/object:Gem::Version
64
- hash: 977940574
61
+ hash: 23
65
62
  segments:
66
63
  - 1
67
64
  - 0
68
65
  - 0
69
- - rc1
70
- version: 1.0.0.rc1
66
+ version: 1.0.0
71
67
  type: :runtime
72
68
  version_requirements: *id003
73
69
  - !ruby/object:Gem::Dependency
@@ -211,14 +207,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
207
  required_rubygems_version: !ruby/object:Gem::Requirement
212
208
  none: false
213
209
  requirements:
214
- - - ">"
210
+ - - ">="
215
211
  - !ruby/object:Gem::Version
216
- hash: 25
212
+ hash: 3
217
213
  segments:
218
- - 1
219
- - 3
220
- - 1
221
- version: 1.3.1
214
+ - 0
215
+ version: "0"
222
216
  requirements: []
223
217
 
224
218
  rubyforge_project: activerecord