Total Ruby noob, trying to figure something out. Looking at the docs
for ActiveRecord:Base, I see no mention of a “where” method in the
method list. Yet one is available. I think that “where” is part of
the ActiveRecord:QueryMethods.
So my question is twofold… first, how is “where” an available method
on my object subclassed from ActiveRecord:Base? Is QueryMethods a
mixin?
Second, looking at the documentation for ActiveRecordBase, how would I
know that “where” is available or how to access it? I realize it’s
talked about in the text of the doc, but in general, how would I know
what methods are available to an object from a mixin?
So my question is twofold… first, how is “where” an available method
on my object subclassed from ActiveRecord:Base? Is QueryMethods a
mixin?
It’s inherited.
Second, looking at the documentation for ActiveRecordBase, how would I
know that “where” is available or how to access it? I realize it’s
talked about in the text of the doc, but in general, how would I know
what methods are available to an object from a mixin?
It’s inherited. If you are inheriting from ActiveRecord::Base it will be
apart of your model. In every example in the documentation you are
inheriting ActiveRecord::Base at the top of your class.
you’ll see that none of the methods have any documentation. :-\
There is information on ARel queries here
and across several blog posts.
I wonder if documentation intentionally left out of the source to keep
it smaller? Anyone have some insight here? Just today I was
wondering where the controller request object methods are documented
(ex: request.path… maybe it is being deprecated?)
Right, but the docs for ActiveRecord::Base show that it derives from
Object, so there’s no “where” method in the chain anywhere. So I
don’t think it’s inherited.
Right, but the docs for ActiveRecord::Base show that it derives from
Object, so there’s no “where” method in the chain anywhere. So I
don’t think it’s inherited.
Start a Rails 3 app. Create a model called Foo without inheriting
ActiveRecord.
class Foo
end
Start the Rails console:
rails console
Run the following command:
Foo.methods.sort
These are all the methods available to the class from just being in
Rails.
The “where” method is not among them.
Exit the console and edit the class to inherit ActiveRecord::Base.
class Foo < ActiveRecord::Base
end
Start the console again and re-run the command. In the bottom of that
list
you will find the method “where”, inherited from ActiveRecord::Base.
Exit the console and edit the class to inherit ActiveRecord::Base.
class Foo < ActiveRecord::Base
end
Start the console again and re-run the command. In the bottom of that list
you will find the method “where”, inherited from ActiveRecord::Base.
B.
Ok, now we’re getting somewhere…
Looking at the source code for ActiveRecord::Base, I do NOT see
“where” defined on ActiveRecord::Base. Nor is it defined in any
superclass (Object). Nor do I see it defined in the docs (under
methods).
So where the heck is it coming from? And if it’s not defined in the
docs, how would I know about it?