# Exists? && new? undefined in ActiveRecord::Base?

**URL:** <https://www.ruby-forum.com/t/exists-new-undefined-in-activerecord-base/155977>\
**Category:** Rails\
**Created:** [December 18, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/exists-new-undefined-in-activerecord-base/155977 "2008-12-18T20:11:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [December 18, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/exists-new-undefined-in-activerecord-base/155977/1 "2008-12-18T20:11:14Z")

</div>

I’ve got a trivial Order class:

class Order \< ActiveRecord::Base  
end

From the console:

Loading development environment (Rails 2.1.2)

> > o = Order.new  
> > =\> #\<Order id: nil, partner\_account\_id: nil, delivery\_status: nil,  
> > payment\_status: nil, stock\_status: nil, complete: nil, admin\_notes:  
> > nil, partner\_notes: nil, created\_at: nil, updated\_at: nil\>
> 
> > o.exists?  
> > NoMethodError: undefined method `exists?' for #<Order:0x7ffd7eabcfd8> from /home/tim/projects/distrome/trunk/vendor/rails/ activerecord/lib/active_record/attribute_methods.rb:251:in`method\_missing’  
> > from (irb):2
> 
> > o.new?  
> > NoMethodError: undefined method `new?' for #<Order:0x7ffd7eabcfd8> from /home/tim/projects/distrome/trunk/vendor/rails/ activerecord/lib/active_record/attribute_methods.rb:251:in`method\_missing’  
> > from (irb):3

I’ve looked at the source and the methods are there. How can this  
be???

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [December 18, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/exists-new-undefined-in-activerecord-base/155977/2 "2008-12-18T20:23:31Z")

</div>

On 18 Dec 2008, at 19:10, Tim McIntyre wrote:

> =\> #\<Order id: nil, partner\_account\_id: nil, delivery\_status: nil,  
> from /home/tim/projects/distrome/trunk/vendor/rails/  
> activerecord/lib/active\_record/attribute\_methods.rb:251:in  
> `method\_missing’  
> from (irb):3
> 
> I’ve looked at the source and the methods are there. How can this  
> be???

exists? is a class method, so Order.exists?( id\_or\_conditions) (what  
would o.exists? even mean?)

There is no new? method, although there is one on  
ActiveResource::Base. Did you mean o.new\_record?

Fred

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [December 18, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/exists-new-undefined-in-activerecord-base/155977/3 "2008-12-18T20:34:04Z")

</div>

my bad… thought I was loosing my mind there… I was looking at the  
code for ActiveResource::Base ☹

I was thinking that o.exists? would return whether the record exists  
in the database, basically what new\_record? does.

I knew it had to be something obvious… Sorry for the distraction and  
thanks for setting me straight Fredrick!

Tim

On Dec 18, 11:22 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
