# Searching Across Multiple Models

**URL:** <https://www.ruby-forum.com/t/searching-across-multiple-models/113058>\
**Category:** Rails\
**Created:** [August 27, 2007, 3:36am UTC](https://www.ruby-forum.com/t/searching-across-multiple-models/113058 "2007-08-27T03:36:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [August 27, 2007, 3:36am UTC](https://www.ruby-forum.com/t/searching-across-multiple-models/113058/1 "2007-08-27T03:36:20Z")

</div>

Hello All,

I am currently looking for the easiest way to search across multiple  
models.

Suppose I am implementing an online inventory look-up system. A user  
will search for a product and a list of stores within 10 miles that  
have that product in stock will be returned.

I have two models: Store and Product. Store contains all the location  
information. Product contains all the product information. Store  
has\_many Products.

I would imagine that I could carry this query out in two steps: 1)  
Retrieve a list of all stores within 10 miles. 2) Search for products  
within those stores.

This two-step process seems a little klunky. Is there any better way  
to do this efficiently in Rails?

I am using GeoKit to calculate distances.

Thanks in advance,  
-Tom
