I made a patch to allow eager loading to exclude specified columns on the eagerly-loaded models. If you have a model that you want to load for a specific reason -- like, say, you have lots of users, and you want to grab all their posts but exclude the posts'' bodies -- you can now specify that by going: User.find(:all, :include => {:posts => {:except => :body}}) I found this useful in my application when I was trying to grab a huge amount of emails and didn''t want to include their bodies. Without body loading, the emails loaded in a a few milliseconds: with the bodies included they took lots longer. The ticket for this change is here: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3662-exclude-fields-from-eager-loaded-models -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
On Tue, Jan 5, 2010 at 12:06 PM, Josh Symonds <veraticus@gmail.com> wrote:> I made a patch to allow eager loading to exclude specified columns on the > eagerly-loaded models. If you have a model that you want to load for a > specific reason -- like, say, you have lots of users, and you want to grab > all their posts but exclude the posts'' bodies -- you can now specify that by > going: > > User.find(:all, :include => {:posts => {:except => :body}})Isn''t this already supported syntax (which would load the :except association for posts and the :body association for excepts)? Not that I think having an association named :except is a good idea, but it''s something to consider. Jeremy -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
This isn''t *necessarily* a problem. If you have an association named :except you can still eagerly load it using either the array syntax: User.find(:all, :include => [:comments, :except]) Or just the regular symbol notation: User.find(:all, :include => :except) If you include it in the hash notation though, it definitely will think you''re going to specify column names to remove from the select: User.find(:all, :include => {:comments => :except}) Will now bomb out, where before it would assume that you want to include comments and then include except on comments, like you said. In making the patch I figured the amount of people who would be helped by the performance improvements probably outweighs the number of people who have associations named "except." But hey, I could be wrong. Josh On Tue, Jan 5, 2010 at 2:30 PM, Jeremy Evans <jeremyevans0@gmail.com> wrote:> On Tue, Jan 5, 2010 at 12:06 PM, Josh Symonds <veraticus@gmail.com> wrote: > > I made a patch to allow eager loading to exclude specified columns on the > > eagerly-loaded models. If you have a model that you want to load for a > > specific reason -- like, say, you have lots of users, and you want to > grab > > all their posts but exclude the posts'' bodies -- you can now specify that > by > > going: > > > > User.find(:all, :include => {:posts => {:except => :body}}) > > Isn''t this already supported syntax (which would load the :except > association for posts and the :body association for excepts)? Not > that I think having an association named :except is a good idea, but > it''s something to consider. > > Jeremy > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
I read the Rails 3 Beta call email and I wanted to try to raise this ticket again to maybe get it a bit more visibility before the beta comes out. Anyone feel like commenting on this patch? I''ve found it helpful, anyway! On Tue, Jan 5, 2010 at 2:38 PM, Josh Symonds <veraticus@gmail.com> wrote:> This isn''t *necessarily* a problem. If you have an association named > :except you can still eagerly load it using either the array syntax: > > User.find(:all, :include => [:comments, :except]) > > Or just the regular symbol notation: > > User.find(:all, :include => :except) > > If you include it in the hash notation though, it definitely will think > you''re going to specify column names to remove from the select: > > User.find(:all, :include => {:comments => :except}) > > Will now bomb out, where before it would assume that you want to include > comments and then include except on comments, like you said. In making the > patch I figured the amount of people who would be helped by the performance > improvements probably outweighs the number of people who have associations > named "except." But hey, I could be wrong. > > Josh > > On Tue, Jan 5, 2010 at 2:30 PM, Jeremy Evans <jeremyevans0@gmail.com>wrote: > >> On Tue, Jan 5, 2010 at 12:06 PM, Josh Symonds <veraticus@gmail.com> >> wrote: >> > I made a patch to allow eager loading to exclude specified columns on >> the >> > eagerly-loaded models. If you have a model that you want to load for a >> > specific reason -- like, say, you have lots of users, and you want to >> grab >> > all their posts but exclude the posts'' bodies -- you can now specify >> that by >> > going: >> > >> > User.find(:all, :include => {:posts => {:except => :body}}) >> >> Isn''t this already supported syntax (which would load the :except >> association for posts and the :body association for excepts)? Not >> that I think having an association named :except is a good idea, but >> it''s something to consider. >> >> Jeremy >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To post to this group, send email to rubyonrails-core@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-core?hl=en. >> >> >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
I don''t believe this should be in core for a few reasons : 1) It''s not needed very often 2) Difficult to make it work with eager loading. Your patch only deals with preloading. 3) I''d prefer using a plugin like http://github.com/mcmire/ar_attr_lazy/ On Wed, Jan 20, 2010 at 8:49 PM, Josh Symonds <veraticus@gmail.com> wrote:> I read the Rails 3 Beta call email and I wanted to try to raise this ticket > again to maybe get it a bit more visibility before the beta comes out. > Anyone feel like commenting on this patch? I''ve found it helpful, anyway! > > On Tue, Jan 5, 2010 at 2:38 PM, Josh Symonds <veraticus@gmail.com> wrote: >> >> This isn''t *necessarily* a problem. If you have an association named >> :except you can still eagerly load it using either the array syntax: >> >> User.find(:all, :include => [:comments, :except]) >> >> Or just the regular symbol notation: >> >> User.find(:all, :include => :except) >> >> If you include it in the hash notation though, it definitely will think >> you''re going to specify column names to remove from the select: >> >> User.find(:all, :include => {:comments => :except}) >> >> Will now bomb out, where before it would assume that you want to include >> comments and then include except on comments, like you said. In making the >> patch I figured the amount of people who would be helped by the performance >> improvements probably outweighs the number of people who have associations >> named "except." But hey, I could be wrong. >> >> Josh >> >> On Tue, Jan 5, 2010 at 2:30 PM, Jeremy Evans <jeremyevans0@gmail.com> >> wrote: >>> >>> On Tue, Jan 5, 2010 at 12:06 PM, Josh Symonds <veraticus@gmail.com> >>> wrote: >>> > I made a patch to allow eager loading to exclude specified columns on >>> > the >>> > eagerly-loaded models. If you have a model that you want to load for a >>> > specific reason -- like, say, you have lots of users, and you want to >>> > grab >>> > all their posts but exclude the posts'' bodies -- you can now specify >>> > that by >>> > going: >>> > >>> > User.find(:all, :include => {:posts => {:except => :body}}) >>> >>> Isn''t this already supported syntax (which would load the :except >>> association for posts and the :body association for excepts)? Not >>> that I think having an association named :except is a good idea, but >>> it''s something to consider. >>> >>> Jeremy >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Core" group. >>> To post to this group, send email to rubyonrails-core@googlegroups.com. >>> To unsubscribe from this group, send email to >>> rubyonrails-core+unsubscribe@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-core?hl=en. >>> >>> >>> >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. >-- Cheers! - Pratik http://m.onkey.org | http://twitter.com/lifo -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.