i''m a little confused here on what''s happening. i have two tables ITEMS and ITEM_TYPES ITEMS (belongs_to :item_type) id name item_type_id ITEM_TYPES id name here is my Item.rb model code for my query: find(:all, :select => ''items.name, item_types.name'', :include => :item_type, :conditions => [''item_types.name = ? OR item_types.name = ? OR item_types.name = ? OR item_types.name = ?'', ''Material'', ''Weapon'', ''Armor'', ''Accessory''], :order => ''items.name'') currently it is selecting all fields in the ITEM table and not using the :select that i have entered. if i comment out the :conditions parameter the :select works properly. i''m sure it''s something to do with the linking to the item_types table. does anyone know how i can get the above :select working properly? thanks! -- Posted via http://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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The find''s :select option is ignored when you combine it with the :include option. On Apr 16, 8:58 pm, Scott Kulik <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> i''m a little confused here on what''s happening. > > i have two tables ITEMS and ITEM_TYPES > > ITEMS (belongs_to :item_type) > id > name > item_type_id > > ITEM_TYPES > id > name > > here is my Item.rb model code for my query: > > find(:all, > :select => ''items.name, item_types.name'', > :include => :item_type, > :conditions => [''item_types.name = ? OR item_types.name = ? OR > item_types.name = ? OR item_types.name = ?'', ''Material'', ''Weapon'', > ''Armor'', ''Accessory''], > :order => ''items.name'') > > currently it is selecting all fields in the ITEM table and not using the > :select that i have entered. > > if i comment out the :conditions parameter the :select works properly. > i''m sure it''s something to do with the linking to the item_types table. > does anyone know how i can get the above :select working properly? > > thanks! > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold wrote:> The find''s :select option is ignored when you combine it with > the :include option. > > On Apr 16, 8:58�pm, Scott Kulik <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>thanks. i removed the include and did my joins manually. i guess that''s probably the best way: find(:all, :select => ''item_types.name, items.id, items.name'', :joins => ''join item_types on items.item_type_id = item_types.id'', :conditions => [''item_types.name = ? OR item_types.name = ? OR item_types.name = ? OR item_types.name = ?'', ''Material'', ''Weapon'', ''Armor'', ''Accessory''], :order => ''items.name'') -- Posted via http://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The whole operation smells like a somewhat premature operation, unless either Item or ItemType has a whole bunch of fields you didn''t mention. Why not just let AR work the way it does? Item.find(:all, :include => :item_type, :conditions => { :''item_types.name'' => %w(Material Weapon Armor Accessory) }) (that last bit changes the chain of ''OR''s above into an IN statement, which is a cheap optimization, and easier to change later...) --Matt Jones On Apr 16, 9:49 pm, Scott Kulik <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Harold wrote: > > The find''s :select option is ignored when you combine it with > > the :include option. > > > On Apr 16, 8:58 pm, Scott Kulik <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > thanks. i removed the include and did my joins manually. i guess > that''s probably the best way: > > find(:all, > :select => ''item_types.name, items.id, items.name'', > :joins => ''join item_types on items.item_type_id > item_types.id'', > :conditions => [''item_types.name = ? OR item_types.name = ? OR > item_types.name = ? OR item_types.name = ?'', ''Material'', ''Weapon'', > ''Armor'', ''Accessory''], > :order => ''items.name'') > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---