# Re: Looking for comments on a rails patch, lazy association instantiation)

**URL:** <https://www.ruby-forum.com/t/re-looking-for-comments-on-a-rails-patch-lazy-association-instantiation/118552>\
**Category:** Ruby\
**Created:** [October 28, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/re-looking-for-comments-on-a-rails-patch-lazy-association-instantiation/118552 "2007-10-28T18:43:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rykkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@rykkers](https://www.ruby-forum.com/u/rykkers)\
**Post date:** [October 28, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/re-looking-for-comments-on-a-rails-patch-lazy-association-instantiation/118552/1 "2007-10-28T18:43:46Z")

</div>

Thanks to a great suggestion by Josh S… I’ve spent the past two  
days completely re-working the code I submitted in the eariler patch.

The new patch; [http://dev.rubyonrails.org/ticket/10012](http://dev.rubyonrails.org/ticket/10012)  
accomplishes the same results, but with a much better api.

The earlier patch added a new option for use with :include which named  
associated AR classes not to be eagerly loaded. This negative  
specification was awkward.

At Josh’s suggestion, the new patch extends the values acceptable to  
the existing :joins option.  
If a string it used things will work as before. If not, the values  
take the same form as values for :include, i.e. symbols, hashes, and  
arrays of symbols and hashes. These are used to construct a join  
clause for the sql query, and the same code used to process the  
results for the :include option, patched to be aware of these new  
active record joins, instantiates the result objects, stripping out  
the extra attributes from the join, so that the results are writable  
(unlike those returned from :joins with a string value.

This allows you to add tables to a query for use in the conditions,  
but not instantiate unneeded associated objects when they will not  
(all) be needed. In addition since this generates a regular inner  
join rather than the left outer join generated by :include, less data  
may be returned to be processed in cases where there are records with  
missing associated records.

I look forward to feedback.

On 10/24/07, Rick DeNatale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://dev.rubyonrails.org/ticket/9923](http://dev.rubyonrails.org/ticket/9923)  
> –  
> Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![rykkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@rykkers](https://www.ruby-forum.com/u/rykkers)\
**Post date:** [October 28, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/re-looking-for-comments-on-a-rails-patch-lazy-association-instantiation/118552/2 "2007-10-28T19:08:22Z")

</div>

On Oct 28, 12:43 pm, “Rick DeNatale” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> At Josh’s suggestion, the new patch extends the values acceptable to  
> This allows you to add tables to a query for use in the conditions,
> 
> > Prompted by some discussion on rails-talk last week, I worked up a
> 
> –  
> Rick DeNatale

Looks good, I’ll check it out. With the RC fast approaching, I can’t  
guarantee it’ll make it into Rails 2.0. If anyone is interested in  
this, please try it out on your apps and give us feedback.
