# Rails3: Arel finder discovery!

**URL:** <https://www.ruby-forum.com/t/rails3-arel-finder-discovery/193476>\
**Category:** Rails\
**Created:** [August 18, 2010, 12:24pm UTC](https://www.ruby-forum.com/t/rails3-arel-finder-discovery/193476 "2010-08-18T12:24:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AppleII717](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@AppleII717](https://www.ruby-forum.com/u/AppleII717)\
**Post date:** [August 18, 2010, 12:24pm UTC](https://www.ruby-forum.com/t/rails3-arel-finder-discovery/193476/1 "2010-08-18T12:24:10Z")

</div>

Rail3 Arel finders are just great, but you can’t find a lot of example  
on how powerful they really are.

I made a discovery, just experimenting with some chaining.

List say you have  
Foo has may Bars

@foo = Foo.find(1)

@bar = @foo.bars

That would give you all the bars related to foo(1)

But you can also do:

@bar = @foo.bars.order(:name).where(:elem =\> “something”)

I guess it is like scopes, just not defined in the model.

I don’t know if that was possible in rails2 (e.g., @bar  
@foo.bars.find(:conditions =\> “xxx”))

Not sure I have a use for it, but it was interesting that you can  
filter a nested has\_many relationship.

Steve A.

---

<div class="post-metadata">

**Author:** ![AppleII717](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@AppleII717](https://www.ruby-forum.com/u/AppleII717)\
**Post date:** [August 18, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/rails3-arel-finder-discovery/193476/2 "2010-08-18T13:36:11Z")

</div>

On Aug 18, 5:18 am, AppleII717 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
\>

> I don’t know if that was possible in rails2 (e.g., @bar  
> @foo.bars.find(:conditions =\> “xxx”))
> 
> Not sure I have a use for it, but it was interesting that you can  
> filter a nested has\_many relationship.

I guess it was a learning experience for me. I don’t think I every saw  
an example where you can filter a nested relation. Tried it in rails  
2.3.8 and it worked - so it was not a discovery - except for me.

---

<div class="post-metadata">

**Author:** ![AppleII717](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@AppleII717](https://www.ruby-forum.com/u/AppleII717)\
**Post date:** [August 19, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/rails3-arel-finder-discovery/193476/3 "2010-08-19T19:11:19Z")

</div>

Also note that you can chain “magic finders” off the association as  
well; so

@foo.bars.find\_by\_name(‘xyzzy’)

will work.

–Matt J.
