Hi! I''m looking for a good tutorial that explains the main points of performing queries with Rails. I do have AWDWR and have read the section on ''find'' but I''m looking for something that goes into more detail on how to perform queries across tables. Abstracted from my current application, this is an example: * person has_many sites * site has_one room * room has attributes such as floor# I''d like to learn how to do things like query how many people older than 30 have an office on a floor higher than Level 7. I could ask a specific question relating to what I''m doing, but I think it would be more productive for me to read a tutorial first before I bother you :-) Thanks, Mohit.
On 13/08/06, Mohit Sindhwani <mo_mail@onghu.com> wrote:> > * person has_many sites > * site has_one room > * room has attributes such as floor# > > I''d like to learn how to do things like query how many people older than > 30 have an office on a floor higher than Level 7. >find :conditions => ''age > 30 and room.floornumber > 7'' -- Cheers, Hasan Diwan <hasan.diwan@gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060814/c454e96c/attachment.html
Hasan Diwan wrote:> On 13/08/06, *Mohit Sindhwani* <mo_mail@onghu.com > <mailto:mo_mail@onghu.com>> wrote: > > * person has_many sites > * site has_one room > * room has attributes such as floor# > > I''d like to learn how to do things like query how many people > older than > 30 have an office on a floor higher than Level 7. > > find :conditions => ''age > 30 and room.floornumber > 7'' > -- > Cheers, > Hasan Diwan <hasan.diwan@gmail.com <mailto:hasan.diwan@gmail.com>>Thanks for the quick response, Hasan! I''m actually also keen to read more about how these queries are formulated.. but, I guess this gives me a set of ideas to start with :) Cheers, Mohit.
Hi, I''m trying to build a query that looks like this: @book_pages, @books = paginate(:books, :per_page => 20, :conditions => [''book.author.name like ?'', ''%jim%], :order_by => @sort_order) I want to basically list out all the books by authors with names like ''jim'' - prefer to have this paginated so that I can use my basic paginated list view. However, this throws up an exception: Mysql::Error: Unknown table ''books'' in where clause: SELECT count(*) AS count_all FROM books WHERE (author.name like ''%ha%'') What do you think I''m doing wrong? Thanks Mohit. Hasan Diwan wrote:> On 13/08/06, *Mohit Sindhwani* <mo_mail@onghu.com > <mailto:mo_mail@onghu.com>> wrote: > > * person has_many sites > * site has_one room > * room has attributes such as floor# > > I''d like to learn how to do things like query how many people > older than > 30 have an office on a floor higher than Level 7. > > find :conditions => ''age > 30 and room.floornumber > 7'' > -- > Cheers, > Hasan Diwan <hasan.diwan@gmail.com <mailto:hasan.diwan@gmail.com>>
Max Muermann wrote:>> >> I want to basically list out all the books by authors with names like >> ''jim'' - prefer to have this paginated so that I can use my basic >> paginated list view. However, this throws up an exception: >> > > > @book_pages, @books = paginate(:books, > :per_page => 20, > :conditions > =>[''author.name like ?'', ''%jim%], > :include=>:author > :order_by => > @sort_order) > > Note the :include option. You may want to look that up in the rails > docs - this is off the top of my head, I might have the naming > slightly wrong. > > Max >Hi Max, Thanks for your suggestions - I apologize for replying this late, but my site/ email had died for a while! Cheers Mohit.
> > I want to basically list out all the books by authors with names like > ''jim'' - prefer to have this paginated so that I can use my basic > paginated list view. However, this throws up an exception: >@book_pages, @books = paginate(:books, :per_page => 20, :conditions =>[''author.name like ?'', ''%jim%], :include=>:author :order_by => @sort_order) Note the :include option. You may want to look that up in the rails docs - this is off the top of my head, I might have the naming slightly wrong. Max