diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 18:00:49 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 18:00:49 +0530 |
commit | 2c8f83556bf3ec9861315e11bc070753ef6bd97c (patch) | |
tree | 12e4d36f96644cf8f3493e57b9e7ee31c659a799 /activerecord/lib/active_record/relation.rb | |
parent | b31233485b2ec7be96279448f77c860b0e94279b (diff) | |
download | rails-2c8f83556bf3ec9861315e11bc070753ef6bd97c.tar.gz rails-2c8f83556bf3ec9861315e11bc070753ef6bd97c.tar.bz2 rails-2c8f83556bf3ec9861315e11bc070753ef6bd97c.zip |
Add relation.exists?
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 87f6aa3643..4ca6871d0f 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -139,6 +139,12 @@ module ActiveRecord end end + def exists?(id = nil) + relation = select("#{@klass.quoted_table_name}.#{@klass.primary_key}").limit(1) + relation = relation.where(@klass.primary_key => id) if id + relation.first ? true : false + end + def first if loaded? @records.first |