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


#1

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:inmethod_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:inmethod_missing’
from (irb):3

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


#2

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


#3

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

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