Ruby on Rails
Monday, January 6, 2014
On Monday, January 6, 2014 7:53:22 AM UTC, Ruby-Forum.com User wrote:
I came across this code snippet from my reading:
require 'active_record'
class Order < ActiveRecord::Base
end
order = Order.find(1)
...
Looking at: http://api.rubyonrails.org/ and search for find(), find() is
an instance public method. So why can we call Order.find(1) here?
Shouldn't it be Order.new.find(1)?
No, because although it is a public instance method, it's a public instance method of ActiveRecord::Relation, not of ActiveRecord::Base. ActiveRecord delegates the find method (and the other querying type methods such as where, first, all etc.) to an instance of this
Fred
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ede8e45b-05cd-4a3d-9cf7-ccec9aba52c0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment