Say I have a table with 3 columns: id integer name varchar(50) data text Is there anyway to have active record think that only the columns "id" and "name" exist? Such that it never loads all the text in the "data" column when fetching rows. The idea is we have an external process that reads and write to the data field directly (without active record) but don''t want to make rails have to load this field every time for no reason. 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 -~----------~----~----~----~------~----~------~--~---
use the :select option to find: :select: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not include the joined columns Mike On 7/6/07, Andrew Arrow <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Say I have a table with 3 columns: > > id integer > name varchar(50) > data text > > Is there anyway to have active record think that only the columns "id" > and "name" exist? Such that it never loads all the text in the "data" > column when fetching rows. > > The idea is we have an external process that reads and write to the data > field directly (without active record) but don''t want to make rails have > to load this field every time for no reason. > > 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 -~----------~----~----~----~------~----~------~--~---
but is there a way to enforce this in the model somewhere so no one accidentally calls it without remembering to use :select Mike Garey wrote:> use the :select option to find: > > :select: By default, this is * as in SELECT * FROM, but can be changed > if you for example want to do a join, but not include the joined > columns > > Mike-- 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 -~----------~----~----~----~------~----~------~--~---
Override the find method in your model class... untested but perhaps something like this: def find(*args) without_data do super end end def without_data(&block) with_scope(:find => { :select => ["name"] }, &block) end WARNING! I''ve never implemented anything quite like that so I have no idea how close that code is to working but I think it''s the right idea. good luck! On Jul 6, 11:48 am, Andrew Arrow <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> but is there a way to enforce this in the model somewhere so no one > accidentally calls it without remembering to use :select > > Mike Garey wrote: > > use the :select option to find: > > > :select: By default, this is * as in SELECT * FROM, but can be changed > > if you for example want to do a join, but not include the joined > > columns > > > Mike > > -- > 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tmac wrote:> Override the find method in your model class... untested but perhaps > something like this: > > def find(*args) > without_data do > super > end > endThanks, I got this to work: class Foo < ActiveRecord::Base set_table_name ''foo'' SELECT_FIELDS = [''name''] def self.find(*args) found_hash = false args.each do |arg| if arg.class == Hash found_hash = true arg[:select] = SELECT_FIELDS end end if not found_hash args << {:select => SELECT_FIELDS} end super(*args) end end see any flaws in the logic? -- 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 -~----------~----~----~----~------~----~------~--~---
It seems like what we want is a plug-in that does something like :attr_ignore, which would then define the select fields by taking the @attributes keys and subtracting the items from the :attr_ignore list. Anyone know of such a plug-in? -- 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 -~----------~----~----~----~------~----~------~--~---