# \[ANN\] rails plugin: find\_by\_association

**URL:** <https://www.ruby-forum.com/t/ann-rails-plugin-find-by-association/105947>\
**Category:** Rails\
**Created:** [June 4, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/ann-rails-plugin-find-by-association/105947 "2007-06-04T21:39:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [June 4, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/ann-rails-plugin-find-by-association/105947/1 "2007-06-04T21:39:12Z")

</div>

Greetings,

Buck and Koz show put on a sesssion of do’s and don’t s at railsconf

- an expression of the rails way vision - Helping us to clean up our  
code with smart coding practices

[http://onrails.org/articles/2007/05/20/railsconf-2007-day-4](http://onrails.org/articles/2007/05/20/railsconf-2007-day-4)

During the session they reinforced we should associations instead of  
finders to clean up our code.

…and while demonstrating they left us with a line that read  
something like “Blog.find\_all\_by\_author\_id” - and I thought to  
myself. No, they must be wrong. Don’t associations have the same  
sugar? [I can’t remember the exact code, but a few of us thought the use of the syntax wasn’t quite free…]

Can’t I do Blog.find\_all\_by\_author(author) ?

Banging on our laptops in the lunch space, it seems they don’t exist.

Not for long. This is railsconf.

FindByAssociation gives Active Record dynamic finders for  
associations. Find\_by\_association helps us by determining the join  
conditions, :includes required tables, and builds a where clause for  
our needs.

#Before  
Post.find(:all, :conditions =\> [“tags.id = ?”, tag.id], :include  
=\> :tags)

#After. ahh. joy  
Post.find\_all\_by\_tag(tag)

write up: [http://www.nnovation.ca/2007/6/4/rails-plugin-](http://www.nnovation.ca/2007/6/4/rails-plugin-)  
find\_by\_association

Cheers,  
Jodi  
General Partner  
The nNovation Group inc.  
www.nnovation.ca/blog

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [June 4, 2007, 9:45pm UTC](https://www.ruby-forum.com/t/ann-rails-plugin-find-by-association/105947/2 "2007-06-04T21:45:16Z")

</div>

On Jun 4, 2007, at 9:38 PM, Jodi S. wrote:

> FindByAssociation gives Active Record dynamic finders for  
> associations. Find\_by\_association helps us by determining the join  
> conditions, :includes required tables, and builds a where clause  
> for our needs.

Some months ago I saw a plugin that provides that feature, I think it  
was this one

[http://agilewebdevelopment.com/plugins/](http://agilewebdevelopment.com/plugins/)  
dynamic\_finders\_with\_belongs\_to\_names

– fxn

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [June 4, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/ann-rails-plugin-find-by-association/105947/3 "2007-06-04T21:54:17Z")

</div>

On 4-Jun-07, at 3:44 PM, Xavier N. wrote:

> [http://agilewebdevelopment.com/plugins/](http://agilewebdevelopment.com/plugins/)  
> dynamic\_finders\_with\_belongs\_to\_names
> 
> – fxn

harump!

In addition to belongs\_to, find\_by\_assocations works will all other  
association types.

Really cleans up references to join tables in has\_many, and  
has\_many :thtorugh’s (and has\_and\_belongs\_to\_many).

thanx for the ref Xavier.

Jodi

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [June 5, 2007, 3:03pm UTC](https://www.ruby-forum.com/t/ann-rails-plugin-find-by-association/105947/4 "2007-06-05T15:03:06Z")

</div>

Awesome! Thanks, this is a feature that I have wished for many times.  
nathan
