# Beginner - multiobject searches

**URL:** <https://www.ruby-forum.com/t/beginner-multiobject-searches/53865>\
**Category:** Rails\
**Created:** [February 15, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/beginner-multiobject-searches/53865 "2006-02-15T16:49:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![djmorphine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@djmorphine](https://www.ruby-forum.com/u/djmorphine)\
**Post date:** [February 15, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/beginner-multiobject-searches/53865/1 "2006-02-15T16:49:45Z")

</div>

Hi folks,

Bit confused by rails and the active record stuff for searching across  
tables.

Say I have a property which has an address and I want to search to  
provide a form that takes one item and searches across both the address  
and property tables… how do I go about it?

Thanks in advance

Marty

---

<div class="post-metadata">

**Author:** ![djmorphine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@djmorphine](https://www.ruby-forum.com/u/djmorphine)\
**Post date:** [February 16, 2006, 11:50am UTC](https://www.ruby-forum.com/t/beginner-multiobject-searches/53865/2 "2006-02-16T11:50:20Z")

</div>

I read your question twice and still have no idea what you are trying to  
do :). Perhaps if you made it a little clearer we can help.

Cheers, -Jonny.

---

<div class="post-metadata">

**Author:** ![djmorphine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@djmorphine](https://www.ruby-forum.com/u/djmorphine)\
**Post date:** [February 16, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/beginner-multiobject-searches/53865/3 "2006-02-16T16:13:27Z")

</div>

On 2/15/06, Marty H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi folks,
> 
> Bit confused by rails and the active record stuff for searching across  
> tables.
> 
> Say I have a property which has an address and I want to search to  
> provide a form that takes one item and searches across both the address  
> and property tables… how do I go about it?

Does this help?  
[http://rails.techno-weenie.net/question/2006/1/13/how\_to\_create\_searches\_across\_multiple\_fields\_using\_various\_search\_criteria](http://rails.techno-weenie.net/question/2006/1/13/how_to_create_searches_across_multiple_fields_using_various_search_criteria)

---

<div class="post-metadata">

**Author:** ![djmorphine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@djmorphine](https://www.ruby-forum.com/u/djmorphine)\
**Post date:** [February 16, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/beginner-multiobject-searches/53865/4 "2006-02-16T17:57:48Z")

</div>

Julian ‘Julik’ Tarkhanov wrote:

> On 15-feb-2006, at 16:49, Marty H. wrote:
> 
> > Hi folks,
> > 
> > Bit confused by rails and the active record stuff for searching across  
> > tables.
> > 
> > Say I have a property which has an address and I want to search to  
> > provide a form that takes one item and searches across both the  
> > address  
> > and property tables… how do I go about it?
> 
> If you have many models with the same attribute (and you want to  
> search across these models but in this attribute only)
> 
> [Person, Company].inject([]) do | result, class |  
> result += class.find\_all\_by\_address(address\_query)  
> end

cheers for the help folks.  
did it just using sql for simplicity…

---

<div class="post-metadata">

**Author:** ![djmorphine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@djmorphine](https://www.ruby-forum.com/u/djmorphine)\
**Post date:** [February 16, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/beginner-multiobject-searches/53865/5 "2006-02-16T17:19:58Z")

</div>

On 15-feb-2006, at 16:49, Marty H. wrote:

> Hi folks,
> 
> Bit confused by rails and the active record stuff for searching across  
> tables.
> 
> Say I have a property which has an address and I want to search to  
> provide a form that takes one item and searches across both the  
> address  
> and property tables… how do I go about it?

If you have many models with the same attribute (and you want to  
search across these models but in this attribute only)

[Person, Company].inject([]) do | result, class |  
result += class.find\_all\_by\_address(address\_query)  
end
