Hi, 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? THanks in advance for any help. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Mar 6, 2011 at 8:28 PM, tinkerer13 <tinkerer13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. Thanks, B. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
yeah, i find the docs fairly hard to navigate and I''ve been doing this for a while. Once you figure out where the page is http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html you''ll see that none of the methods have any documentation. :-\ There is information on ARel queries here http://guides.rubyonrails.org/active_record_querying.html 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?) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. On Mar 7, 2:47 pm, Bryan Crossland <bacrossl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Mar 6, 2011 at 8:28 PM, tinkerer13 <tinkere...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > Thanks, > B.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I find it really useful to query the objects themselves. "hello".methods for example will how you methods available to call on that string, etc etc Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now! On 07/03/2011, at 1:28 PM, tinkerer13 <tinkerer13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > 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? > > THanks in advance for any help. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Mar 7, 2011 at 8:48 PM, tinkerer13 <tinkerer13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. B. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 7, 10:12 pm, Bryan Crossland <bacrossl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Loves me some puzzles. OK, I think I have the answer. ActiveRecord::Base has a line in it: delegate :select, :group, :order, :reorder, :except, :limit, :offset, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped The method scoped() is defined in ActiveRecord::NamedScope::ClassMethods, and ActiveRecord::NamedScope is included in ActiveRecord::Base. Far from obvious, but there it is. On Tue, Mar 8, 2011 at 7:00 AM, tinkerer13 <tinkerer13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 7, 10:12 pm, Bryan Crossland <bacrossl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.