Img_0736_small James Miller 2 posts

Hey Ryan,
Curious if you have any suggestions for when you do need to include an association (and its data), but don’t need all the columns of the associated data (or the parent data). Does the :select method work when using :joins and :includes? Is it typically not worth it to exclude the unneeded columns?

Thanks,
James

 
Ryan_bates_cropped_small Ryan Bates 29 posts

Hi James,

That’s a good question. The :select option generally does not work with :include, so you’ll have to use :joins. However :joins does not instantiate the associated models so I doubt that will do what you want either. AFAIK, this is a limitation of Active Record. There doesn’t seem to be an easy solution to this, so I’d say the slight speed boost from :select isn’t worth the trouble here.

That said, there may be some way to do this that I’m not seeing, or it may be added in the future. You may want to ask the question on the Rails mailing list.

2 posts, 2 voices