aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-20 11:22:38 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-20 11:22:38 +0000
commit427fb035a3d03b23e903ca499abf3c1bfa53b10a (patch)
tree3610839d6204b352c896b3c88cd1b19cb97d1c0f /activerecord/lib/active_record/base.rb
parent6fc8e143c6aafa85c7b392f39a912f2545f23f8d (diff)
downloadrails-427fb035a3d03b23e903ca499abf3c1bfa53b10a.tar.gz
rails-427fb035a3d03b23e903ca499abf3c1bfa53b10a.tar.bz2
rails-427fb035a3d03b23e903ca499abf3c1bfa53b10a.zip
Simplify query_attribute by typecasting the attribute value and checking whether it's nil, false, zero or blank. Closes #6659.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5593 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb22
1 files changed, 7 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 864cf43ef3..99c276ef8b 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1976,23 +1976,15 @@ module ActiveRecord #:nodoc:
end
def query_attribute(attr_name)
- attribute = @attributes[attr_name]
- if attribute.kind_of?(Fixnum) && attribute == 0
- false
- elsif attribute.kind_of?(String) && attribute == "0"
- false
- elsif attribute.kind_of?(String) && attribute.empty?
- false
- elsif attribute.nil?
- false
- elsif attribute == false
- false
- elsif attribute == "f"
- false
- elsif attribute == "false"
+ unless value = read_attribute(attr_name)
false
else
- true
+ column = self.class.columns_hash[attr_name]
+ if column.number?
+ !value.zero?
+ else
+ !value.blank?
+ end
end
end