aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-11-23 20:43:06 +0000
committerJosé Valim <jose.valim@gmail.com>2011-11-23 20:43:06 +0000
commite62de52aa398341a29b7ecef4ec9f9df8e1743e2 (patch)
tree3a87677e000259ecc0ced6bc93afc03fea73493b /activerecord/lib/active_record/base.rb
parentafd7140b66e7cb32e1be58d9e44489e6bcbde0dc (diff)
parentfd86a1b6b068df87164d5763bdcd4a323a1e76f4 (diff)
downloadrails-e62de52aa398341a29b7ecef4ec9f9df8e1743e2.tar.gz
rails-e62de52aa398341a29b7ecef4ec9f9df8e1743e2.tar.bz2
rails-e62de52aa398341a29b7ecef4ec9f9df8e1743e2.zip
Merge branch 'master' into serializers
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r--activerecord/lib/active_record/base.rb29
1 files changed, 16 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 360e494af1..7ba67b8540 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -445,7 +445,9 @@ module ActiveRecord #:nodoc:
delegate :first_or_create, :first_or_create!, :first_or_initialize, :to => :scoped
delegate :destroy, :destroy_all, :delete, :delete_all, :update, :update_all, :to => :scoped
delegate :find_each, :find_in_batches, :to => :scoped
- delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped
+ delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins,
+ :where, :preload, :eager_load, :includes, :from, :lock, :readonly,
+ :having, :create_with, :uniq, :to => :scoped
delegate :count, :average, :minimum, :maximum, :sum, :calculate, :to => :scoped
# Executes a custom SQL query against your database and returns all the results. The results will
@@ -708,21 +710,21 @@ module ActiveRecord #:nodoc:
# Returns an array of column objects for the table associated with this class.
def columns
if defined?(@primary_key)
- connection_pool.primary_keys[table_name] ||= primary_key
+ connection.schema_cache.primary_keys[table_name] ||= primary_key
end
- connection_pool.columns[table_name]
+ connection.schema_cache.columns[table_name]
end
# Returns a hash of column objects for the table associated with this class.
def columns_hash
- connection_pool.columns_hash[table_name]
+ connection.schema_cache.columns_hash[table_name]
end
# Returns a hash where the keys are column names and the values are
# default values when instantiating the AR object for this table.
def column_defaults
- connection_pool.column_defaults[table_name]
+ connection.schema_cache.column_defaults[table_name]
end
# Returns an array of column names as strings.
@@ -758,7 +760,7 @@ module ActiveRecord #:nodoc:
# values, eg:
#
# class CreateJobLevels < ActiveRecord::Migration
- # def self.up
+ # def up
# create_table :job_levels do |t|
# t.integer :id
# t.string :name
@@ -772,21 +774,21 @@ module ActiveRecord #:nodoc:
# end
# end
#
- # def self.down
+ # def down
# drop_table :job_levels
# end
# end
def reset_column_information
connection.clear_cache!
undefine_attribute_methods
- connection_pool.clear_table_cache!(table_name) if table_exists?
+ connection.schema_cache.clear_table_cache!(table_name) if table_exists?
@column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
@arel_engine = @relation = nil
end
def clear_cache! # :nodoc:
- connection_pool.clear_cache!
+ connection.schema_cache.clear!
end
def attribute_method?(attribute)
@@ -1354,9 +1356,9 @@ MSG
return nil if condition.blank?
case condition
- when Array; sanitize_sql_array(condition)
- when Hash; sanitize_sql_hash_for_conditions(condition, table_name)
- else condition
+ when Array; sanitize_sql_array(condition)
+ when Hash; sanitize_sql_hash_for_conditions(condition, table_name)
+ else condition
end
end
alias_method :sanitize_sql, :sanitize_sql_for_conditions
@@ -1769,7 +1771,8 @@ MSG
# Returns true if the specified +attribute+ has been set by the user or by a database load and is neither
# nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings).
def attribute_present?(attribute)
- !_read_attribute(attribute).blank?
+ value = _read_attribute(attribute)
+ !value.nil? || (value.respond_to?(:empty?) && !value.empty?)
end
# Returns the column object for the named attribute.