Changeset 4651
- Timestamp:
- 08/03/06 17:16:43 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (1 diff)
- trunk/activerecord/test/finder_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4650 r4651 1 1 *SVN* 2 3 * Added support for conditions on Base.exists? #5689 [josh@joshpeek.com]. Examples: 4 5 assert (Topic.exists?(:author_name => "David")) 6 assert (Topic.exists?(:author_name => "Mary", :approved => true)) 7 assert (Topic.exists?(["parent_id = ?", 1])) 2 8 3 9 * Schema dumper quotes date :default values. [Dave Thomas] trunk/activerecord/lib/active_record/base.rb
r4645 r4651 424 424 425 425 # Returns true if the given +id+ represents the primary key of a record in the database, false otherwise. 426 # You can also pass a set of SQL conditions. 426 427 # Example: 427 428 # Person.exists?(5) 428 def exists?(id) 429 !find(:first, :conditions => ["#{primary_key} = ?", id]).nil? rescue false 429 # Person.exists?(:name => "David") 430 def exists?(conditions) 431 conditions = ["#{primary_key} = ?", conditions] if conditions.is_a?(Fixnum) 432 !find(:first, :conditions => conditions).nil? rescue false 430 433 end 431 434 trunk/activerecord/test/finder_test.rb
r4586 r4651 22 22 def test_exists 23 23 assert (Topic.exists?(1)) 24 assert (Topic.exists?(:author_name => "David")) 25 assert (Topic.exists?(:author_name => "Mary", :approved => true)) 26 assert (Topic.exists?(["parent_id = ?", 1])) 24 27 assert !(Topic.exists?(45)) 25 28 assert !(Topic.exists?("foo"))