Hi all, Is there any way to specify that AR ignore certain columns? I have a project where I have to connect to a legacy DB where I have a very wide read only table (actually a view, but the result is the same). The web app only needs about 1/2 of the columns, the other stuff I don''t need. Other than specifying a select clause on every find (or a named scope that applies the select I need), is there a way to tell ActiveRecord to completely ignore certain columns, or as an alternative declared a named scope to be applied to all finds of a Model, or declare as default :select clause? Any ideas would be greatly appreciated. Thanks, Andrew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A> Spank the legacy programmer who threw everything into one table instead of normalizing it all out B> add an SQL View that only selects what you need, then base the AR on this View... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A. Believe me I''d love to.... He''s 5 states away. :( B. You''re assuming I have control of the DB.... NOT!! I have to deal with what they give me. And yes, it''s a MS SQL Server DB, it''s hosted at the other companies office, on the other end of an encrypted VPN.... Sigh.... Got to love those MS devotees... At least I convinced them to give me read access to the views, rather than doing absolutely everything through stored procedures, which is what they originally wanted. On Jun 21, 9:53 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> A> Spank the legacy programmer who threw everything into one table > instead of normalizing it all out > > B> add an SQL View that only selects what you need, then base the > AR on this View...--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Is there any way to specify that AR ignore certain columns?did you try :select option? You can do this for example: VeryWideTable.find(:all, :select => ''first_field, second_field'') it will produce SELECT first_field, second_field FROM very_wide_tables instead of default SELECT * FROM very_wide_tables It really make sense, if you need to perform queries fast, and don''t want to process big amount of incoming data I hope that it will solve your problems ----------------------------------------------- TRIX - Ruby on Rails Development (available for hire) http://en.trix.pl --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tomek wrote:>> Is there any way to specify that AR ignore certain columns?> You can do this for example: > > VeryWideTable.find(:all, :select => ''first_field, second_field'')or you could move to Merb + DataMapper. http://datamapper.org/why.html look at the bit on "lazy loading" -- 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 -~----------~----~----~----~------~----~------~--~---
Yeah, That''s what I''m doing. I''m trying to DRY up my code with out have to tack on a select on every single find I use. Andrew On Jun 22, 3:14 am, Tomek <bi...-9jBX88ZrXJw@public.gmane.org> wrote:> > Is there any way to specify that AR ignore certain columns? > > did you try :select option? > > You can do this for example: > > VeryWideTable.find(:all, :select => ''first_field, second_field'') > > it will produce SELECT first_field, second_field FROM very_wide_tables > > instead of default SELECT * FROM very_wide_tables > > It really make sense, if you need to perform queries fast, and don''t > want to process big amount of incoming data > > I hope that it will solve your problems > > ----------------------------------------------- > TRIX - Ruby on Rails Development (available for hire)http://en.trix.pl--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---