diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-09 13:50:08 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-09 13:50:08 -0800 |
commit | e0cba3a0fab28f96dc9b5d3a714886583873a7d3 (patch) | |
tree | 8712fd8f0b53b7916ae8549decb86928302f00dc /activerecord/lib/active_record | |
parent | 6c50c07d8dbb0b014e68608fe72f807cbe7f5c45 (diff) | |
parent | e6c98b83cbf4eab8944601754cc8d0e627b55d6f (diff) | |
download | rails-e0cba3a0fab28f96dc9b5d3a714886583873a7d3.tar.gz rails-e0cba3a0fab28f96dc9b5d3a714886583873a7d3.tar.bz2 rails-e0cba3a0fab28f96dc9b5d3a714886583873a7d3.zip |
Merge branch 'master' into instance_reader
* master: (30 commits)
Bump tzinfo. 0.3.31 was released on November 6, 2011.
Fix GH #4909. Dependency on TZInfo move from AR to AS.
moving ordered hash to normal hash because ruby 1.9.3 hash defaultly ordered one
Refactored the OrderedHash related stuff
Replaced OrderedHash usage with Ruby 1.9 Hash
Replaced OrderedHash with Hash for ruby 1.9 series
removed unnecessary code
replacing the orderhash with hash for ruby-1.9
Clean up some wording.
Fix typo.
test title changed corresponding to the test
replaced active support ordered hash to ruby hash on active resource
PostgreSQL does not work in the same way of the other adapters
AR::Relation#pluck: improve to work with joins
Fix match docs
Fix attribute_before_type_cast for serialized attributes. Fixes #4837.
Fix failing request test
Fixes in AMo README
Update README to mention lint.
Trim down Active Model API by removing valid? and errors.full_messages
...
Diffstat (limited to 'activerecord/lib/active_record')
5 files changed, 17 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index 1fe5d9de20..9b1bfa1145 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -110,6 +110,14 @@ module ActiveRecord super end end + + def read_attribute_before_type_cast(attr_name) + if serialized_attributes.include?(attr_name) + super.unserialized_value + else + super + end + end end end end diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 28f52bd270..c4a4c0ad9a 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -212,6 +212,8 @@ module ActiveRecord # The dup method does not preserve the timestamps (created|updated)_(at|on). def initialize_dup(other) cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast) + self.class.initialize_attributes(cloned_attributes) + cloned_attributes.delete(self.class.primary_key) @attributes = cloned_attributes @@ -246,7 +248,7 @@ module ActiveRecord # end # coder = {} # Post.new.encode_with(coder) - # coder # => { 'id' => nil, ... } + # coder # => {"attributes" => {"id" => nil, ... }} def encode_with(coder) coder['attributes'] = attributes end diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index cf315b687c..b82d5b5621 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -3,7 +3,6 @@ require 'yaml' require 'zlib' require 'active_support/dependencies' require 'active_support/core_ext/object/blank' -require 'active_support/ordered_hash' require 'active_record/fixtures/file' if defined? ActiveRecord @@ -508,7 +507,7 @@ module ActiveRecord @name = fixture_name @class_name = class_name - @fixtures = ActiveSupport::OrderedHash.new + @fixtures = {} # Should be an AR::Base type class if class_name.is_a?(Class) diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 6bf3050af9..50239f7cb2 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -177,6 +177,9 @@ module ActiveRecord # Person.where(:confirmed => true).limit(5).pluck(:id) # def pluck(column_name) + if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s) + column_name = "#{table_name}.#{column_name}" + end klass.connection.select_all(select(column_name).arel).map! do |attributes| klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes)) end diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index b6d762c2e2..87dd513880 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -206,8 +206,8 @@ module ActiveRecord # Any subsequent condition chained to the returned relation will continue # generating an empty relation and will not fire any query to the database. # - # This is useful in scenarios where you need a chainable response to a method - # or a scope that could return zero results. + # Used in cases where a method or scope could return zero records but the + # result needs to be chainable. # # For example: # |