diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-19 12:36:53 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-19 12:36:53 -0700 |
commit | a489bfe48bc0fbbb50a472bc66bd42d408c73fcb (patch) | |
tree | 838c9686ec081959b7e6f9b007f290212d3bad25 /activerecord/lib | |
parent | 08c6df8532a1884050c8e9087e9fce9df6528ae2 (diff) | |
parent | 66001f360661fefad89d9e271b9ff75a86b4b886 (diff) | |
download | rails-a489bfe48bc0fbbb50a472bc66bd42d408c73fcb.tar.gz rails-a489bfe48bc0fbbb50a472bc66bd42d408c73fcb.tar.bz2 rails-a489bfe48bc0fbbb50a472bc66bd42d408c73fcb.zip |
Merge pull request #10211 from neerajdotname/4208
fix respond_to? for non selected column
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 22405c5d74..d0c51b77c2 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -163,8 +163,20 @@ module ActiveRecord # person.respond_to('age?') # => true # person.respond_to(:nothing) # => false def respond_to?(name, include_private = false) + name = name.to_s self.class.define_attribute_methods unless self.class.attribute_methods_generated? - super + result = super + + # If the result is false then it means this method is not supported by ActiveModel too + return false unless result + + # If the result is true then check for the select case. + # For queries selecting a subset of columns, return false for unselected columns. + if @attributes.present? && self.class.column_names.include?(name) + return has_attribute?(name) + end + + return true end # Returns +true+ if the given attribute is in the attributes hash, otherwise +false+. |