I''m setting up a new Rails project that is a nice front end for a company''s personnel database with a legacy schema. Unfortunately, the table that contains all the standard information (first name, last name, email address) has some 20+ columns, one of which is a BLOB of a picture of the person. Loading all this takes a while, when the application really only needs the first and last names and email address. Is there a way to tell AR not to load all the columns? I looked through api.rubyonrails.com and didn''t see anything. The app will not be making any inserts or updates to the database, so I don''t have to be concerned about an AR instance having all the data needed to successfully create a new row without violating a database constraint (NOT NULL, etc). Thanks, Blair -- Blair Zajac, Ph.D. CTO, OrcaWare Technologies <blair@orcaware.com> Subversion training, consulting and support http://www.orcaware.com/svn/
Research :select for the find method and if all else fails just use find_by_sql Bob Silva http://www.railtie.net/> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of Blair Zajac > Sent: Thursday, February 02, 2006 9:00 PM > To: rails@lists.rubyonrails.org > Subject: [Rails] Limiting the columns loaded from a legacy db > > I''m setting up a new Rails project that is a nice front end for a > company''s personnel database with a legacy schema. > > Unfortunately, the table that contains all the standard information > (first name, last name, email address) has some 20+ columns, one of > which is a BLOB of a picture of the person. > > Loading all this takes a while, when the application really only > needs the first and last names and email address. > > Is there a way to tell AR not to load all the columns? I looked > through api.rubyonrails.com and didn''t see anything. > > The app will not be making any inserts or updates to the database, so > I don''t have to be concerned about an AR instance having all the data > needed to successfully create a new row without violating a database > constraint (NOT NULL, etc). > > Thanks, > Blair > > -- > Blair Zajac, Ph.D. > CTO, OrcaWare Technologies > <blair@orcaware.com> > Subversion training, consulting and support > http://www.orcaware.com/svn/ > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the tip on :select. Ideally, you could set something that would apply :select for all find methods, including associations, using something like class Person < AR select_columns :first_name, :last_name, :email_address end Regards, Blair On Feb 2, 2006, at 9:16 PM, Bob Silva wrote:> Research :select for the find method and if all else fails just use > find_by_sql > > > > Bob Silva > http://www.railtie.net/ > >> -----Original Message----- >> From: rails-bounces@lists.rubyonrails.org [mailto:rails- >> bounces@lists.rubyonrails.org] On Behalf Of Blair Zajac >> Sent: Thursday, February 02, 2006 9:00 PM >> To: rails@lists.rubyonrails.org >> Subject: [Rails] Limiting the columns loaded from a legacy db >> >> I''m setting up a new Rails project that is a nice front end for a >> company''s personnel database with a legacy schema. >> >> Unfortunately, the table that contains all the standard information >> (first name, last name, email address) has some 20+ columns, one of >> which is a BLOB of a picture of the person. >> >> Loading all this takes a while, when the application really only >> needs the first and last names and email address. >> >> Is there a way to tell AR not to load all the columns? I looked >> through api.rubyonrails.com and didn''t see anything. >> >> The app will not be making any inserts or updates to the database, so >> I don''t have to be concerned about an AR instance having all the data >> needed to successfully create a new row without violating a database >> constraint (NOT NULL, etc). >> >> Thanks, >> Blair
Model.find(:all, :select "normal sql code fragment goes here... i.e. first_name, last_name, email_address") bruce On 2-Feb-06, at 10:00 PM, Blair Zajac wrote:> I''m setting up a new Rails project that is a nice front end for a > company''s personnel database with a legacy schema. > > Unfortunately, the table that contains all the standard information > (first name, last name, email address) has some 20+ columns, one of > which is a BLOB of a picture of the person. > > Loading all this takes a while, when the application really only > needs the first and last names and email address. > > Is there a way to tell AR not to load all the columns? I looked > through api.rubyonrails.com and didn''t see anything. > > The app will not be making any inserts or updates to the database, > so I don''t have to be concerned about an AR instance having all the > data needed to successfully create a new row without violating a > database constraint (NOT NULL, etc). > > Thanks, > Blair > > -- > Blair Zajac, Ph.D. > CTO, OrcaWare Technologies > <blair@orcaware.com> > Subversion training, consulting and support > http://www.orcaware.com/svn/ > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Oops! Model.find(:all, :select=>"sql code fragment goes here... ie the usual select statement you would have used minus the word select) eg Model.find(:all, :select=>"first_name, last_name, email_address") bruce On 2-Feb-06, at 10:46 PM, Bruce Balmer wrote:> Model.find(:all, :select "normal sql code fragment goes here... > i.e. first_name, last_name, email_address") > > bruce > > > On 2-Feb-06, at 10:00 PM, Blair Zajac wrote: > >> I''m setting up a new Rails project that is a nice front end for a >> company''s personnel database with a legacy schema. >> >> Unfortunately, the table that contains all the standard >> information (first name, last name, email address) has some 20+ >> columns, one of which is a BLOB of a picture of the person. >> >> Loading all this takes a while, when the application really only >> needs the first and last names and email address. >> >> Is there a way to tell AR not to load all the columns? I looked >> through api.rubyonrails.com and didn''t see anything. >> >> The app will not be making any inserts or updates to the database, >> so I don''t have to be concerned about an AR instance having all >> the data needed to successfully create a new row without violating >> a database constraint (NOT NULL, etc). >> >> Thanks, >> Blair >> >> -- >> Blair Zajac, Ph.D. >> CTO, OrcaWare Technologies >> <blair@orcaware.com> >> Subversion training, consulting and support >> http://www.orcaware.com/svn/ >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On February 3, 2006 06:22, Bruce Balmer wrote:> > Model.find(:all, :select=>"sql code fragment goes here... ie the > usual select statement you would have used minus the word select) > > > > > bruce > > > > On 2-Feb-06, at 10:00 PM, Blair Zajac wrote: > >> I''m setting up a new Rails project that is a nice front end for a > >> company''s personnel database with a legacy schema. > >> > >> Unfortunately, the table that contains all the standard > >> information (first name, last name, email address) has some 20+ > >> columns, one of which is a BLOB of a picture of the person. > >> > >> Loading all this takes a while, when the application really only > >> needs the first and last names and email address. > >> > >> Is there a way to tell AR not to load all the columns? I looked > >> through api.rubyonrails.com and didn''t see anything. > >> > >> The app will not be making any inserts or updates to the database, > >> so I don''t have to be concerned about an AR instance having all > >> the data needed to successfully create a new row without violating > >> a database constraint (NOT NULL, etc). > >> > >> Thanks, > >> BlairUnfortunately that doesn''t work when you''re also fetching associations with :include. Also, unless you explicitly select them in your :select snippet, when you join tables into your query their values won''t be picked up by the AR object (since they''re not being selected). If that''s a problem, I guess you should override the find method with your own. Luca