I have models with large TEXT, BLOB columns and I don''t wanna fetch them everytime. Is it possible to omit columns when fetching records from DB? Sorry, if it''s trivial, but I can''t find helpful information in docs.
Christer Nilsson
2006-Apr-23 09:33 UTC
[Rails] Re: ActiveRecord: Exclude some columns while fetching
Two alternatives: 1) Define a View, not displaying your blobs. 2) Use find_by_sql. Mention the columns you need. Christer zven wrote:> I have models with large TEXT, BLOB columns and I don''t wanna fetch them > everytime. Is it possible to omit columns when fetching records from DB? > Sorry, if it''s trivial, but I can''t find helpful information in docs.-- Posted via http://www.ruby-forum.com/.
Brian V Hughes
2006-Apr-23 15:21 UTC
[Rails] Re: ActiveRecord: Exclude some columns while fetching
Third alternative: create a new table that just holds the blob data. Then make this table a has_one association off the table that you do all the searching in. Basically, you keep the main table for all the meta data related to the blobs (which you''re always doing finds on) and only when you need to display the full details of one of those records do you then build the find with a :include to the has_one table. It''s a little more bookkeeping in your controllers, but it''s a technique I''ve used several times and it works really well. I also think it''s one of the more Rails-like solutions to this kind of problem. One thing to keep in mind, if you haven''t noticed that your finds on this model are coming back a little slower than you would like, using any of these solutions would be "premature optimization", which goes against normal Agile Developement practices. Basically, if the database has no trouble giving you the TEXT and BLOB fields on every find request, why should you care... -Brian On Apr 23, 2006, at 05:32 AM, Christer Nilsson wrote:> Two alternatives: > > 1) Define a View, not displaying your blobs. > 2) Use find_by_sql. Mention the columns you need. > > Christer > > zven wrote: >> I have models with large TEXT, BLOB columns and I don''t wanna >> fetch them >> everytime. Is it possible to omit columns when fetching records >> from DB? >> Sorry, if it''s trivial, but I can''t find helpful information in docs.
Bruno Celeste
2006-Apr-23 15:34 UTC
[Rails] Re: ActiveRecord: Exclude some columns while fetching
You can use :select option in find method like this: Model.find :all, :select => "id, name" On 4/23/06, Brian V Hughes <brianvh@alum.dartmouth.org> wrote:> > Third alternative: create a new table that just holds the blob data. > Then make this table a has_one association off the table that you do > all the searching in. Basically, you keep the main table for all the > meta data related to the blobs (which you''re always doing finds on) > and only when you need to display the full details of one of those > records do you then build the find with a :include to the has_one table. > > It''s a little more bookkeeping in your controllers, but it''s a > technique I''ve used several times and it works really well. I also > think it''s one of the more Rails-like solutions to this kind of > problem. One thing to keep in mind, if you haven''t noticed that your > finds on this model are coming back a little slower than you would > like, using any of these solutions would be "premature optimization", > which goes against normal Agile Developement practices. Basically, if > the database has no trouble giving you the TEXT and BLOB fields on > every find request, why should you care... > > -Brian > > On Apr 23, 2006, at 05:32 AM, Christer Nilsson wrote: > > Two alternatives: > > > > 1) Define a View, not displaying your blobs. > > 2) Use find_by_sql. Mention the columns you need. > > > > Christer > > > > zven wrote: > >> I have models with large TEXT, BLOB columns and I don''t wanna > >> fetch them > >> everytime. Is it possible to omit columns when fetching records > >> from DB? > >> Sorry, if it''s trivial, but I can''t find helpful information in docs. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Alex Wayne
2006-Apr-23 18:43 UTC
[Rails] Re: Re: ActiveRecord: Exclude some columns while fetching
Bruno Celeste wrote:> You can use :select option in find method like this: > Model.find :all, :select => "id, name"This is the right answer, find_by_sql is way overkill for this. -- Posted via http://www.ruby-forum.com/.