Would like to use ActiveRecord find for multiple table lookups with sort order on parent table. Example: Item table belongs to Category and Section tables. Category and Section tables have only 2 attributes: id, text field (category and section). Item has many attributes in addition to category_id & section_id. 1. Sort items by category or section TEXT field not the id fields. 2. Be able to update the Item attributes but not category or section. A. Use find_by_sql? B. Use find and ":include" option. C. Use ":from" option to refer to an SQL view of the joined tables? i. Then switch to an updatable Item form? D. Use some other approach? Best regards, Ken Wagner Sugar Creek, Missouri The "Show Me" state. -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Go with B. Items.find(:all, :include=>[:category, :section], :order=>"categories.name, sections.name, items.name") The key is the :order option. On Feb 19, 8:45 pm, Ken Wagner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Would like to use ActiveRecord find for multiple table lookups with sort > order on parent table. > > Example: Item table belongs to Category and Section tables. Category and > Section tables have only 2 attributes: id, text field (category and > section). Item has many attributes in addition to category_id & > section_id. > > 1. Sort items by category or section TEXT field not the id fields. > 2. Be able to update the Item attributes but not category or > section. > > A. Use find_by_sql? > B. Use find and ":include" option. > C. Use ":from" option to refer to an SQL view of the joined tables? > i. Then switch to an updatable Item form? > D. Use some other approach? > > Best regards, > > Ken Wagner > Sugar Creek, Missouri > The "Show Me" state. > -- > Posted viahttp://www.ruby-forum.com.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> Go with B. > > Items.find(:all, :include=>[:category, :section], > :order=>"categories.name, > sections.name, items.name") > > The key is the :order option. > > On Feb 19, 8:45 pm, Ken Wagner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Works like a charm! A little tweaking and the rails magic delights once again. Rails is extraordinarily amazing. (Once you know how it works. :) If only the documentation and examples were a bit more illuminating. Sigh. Many thanks, Andy. -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ken Wagner wrote:> AndyV wrote: > > If only the documentation and examples were a bit more illuminating. > Sigh. > > > Many thanks, Andy.Offtopic but I /sign this "petition". :) -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---