# Search two related tables

**URL:** <https://www.ruby-forum.com/t/search-two-related-tables/135147>\
**Category:** Ferret\
**Created:** [April 18, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/search-two-related-tables/135147 "2008-04-18T13:25:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [April 18, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/search-two-related-tables/135147/1 "2008-04-18T13:25:48Z")

</div>

Hi, It would be trulely appreciated if anyone can give me some advise on  
this.  
I have two related tables titles and authors. Using acts\_as\_ferret, I  
can search by title name. However, when search by author name or ausname  
in this case, I only get “sorry, found 0 item”.

class Title \< ActiveRecord::Base  
acts\_as\_ferret :additional\_fields =\> [:author\_name]  
belongs\_to :author

## def author\_name return author.ausname end

## class Author \< ActiveRecord::Base has\_many :titles end

def search  
if params[:q]  
query = params[:q]  
@titles = Title.find\_by\_contents(query)  
unless @titles.size \> 0  
flash.now[:notice\_not\_found] = “Sorry, found 0 item”  
end  
render :action =\> ‘search\_result’  
end  
end

---

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [April 24, 2008, 8:14am UTC](https://www.ruby-forum.com/t/search-two-related-tables/135147/2 "2008-04-24T08:14:49Z")

</div>

On Fri, Apr 18, 2008 at 01:25:49PM +0200, Katsuo I. wrote:

> Hi, It would be trulely appreciated if anyone can give me some advise on  
> this.  
> I have two related tables titles and authors. Using acts\_as\_ferret, I  
> can search by title name. However, when search by author name or ausname  
> in this case, I only get “sorry, found 0 item”.

Did you have a look at your log files? Maybe author is nil when  
acts\_as\_ferret calls the author\_name method. Aaf logs every field and  
value it adds to the index so you should pretty easily find out what’s  
going on.

Cheers,  
Jens

–  
Jens Krämer  
Finkenlust 14, 06449 Aschersleben, Germany  
VAT Id DE251962952  
[http://www.jkraemer.net/](http://www.jkraemer.net/) - Blog  
[http://www.omdb.org/](http://www.omdb.org/) - The new free film database
