# Habtm and ferret

**URL:** <https://www.ruby-forum.com/t/habtm-and-ferret/127953>\
**Category:** Rails\
**Created:** [February 3, 2008, 4:42am UTC](https://www.ruby-forum.com/t/habtm-and-ferret/127953 "2008-02-03T04:42:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan\_stegall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jonathan\_stegall](https://www.ruby-forum.com/u/jonathan_stegall)\
**Post date:** [February 3, 2008, 4:42am UTC](https://www.ruby-forum.com/t/habtm-and-ferret/127953/1 "2008-02-03T04:42:16Z")

</div>

Hello,

I’ve been working on a specific project for longer than I like to  
think about. At some point, I had ferret working in such a way that it  
would search fields in the HABTM relationship. Now, though, it only  
searches fields in the specific model where the search is located. The  
application is structured like this:

Models:

providers  
procedures  
types  
destinations  
…

provider is where the search in question is located. Thus, it is at  
[http://localhost:3000/provider/search/](http://localhost:3000/provider/search/). A provider  
has\_and\_belongs\_to\_many procedures, types, and destinations. Thus,  
when I search at the above URL, I want my search to take values that  
correspond to those models, as well as the provider model.

provider.rb:

1. acts\_as\_ferret :additional\_fields =\> [
2. 

```
                                   :procedure_name,

```

3. 

```
                                   :type_name,

```

4. 

```
                                   :type_field,

```

5. 

```
                                   :destination_name

```

6. 

```
                                   ]

```

7. has\_and\_belongs\_to\_many :types, :join\_table =\>  
“types\_providers”
8. has\_and\_belongs\_to\_many :procedures, :join\_table =\>  
“procedures\_providers”
9. has\_and\_belongs\_to\_many :destinations, :join\_table =\>  
“destinations\_providers”
10. 
11. def procedure\_name
12. 

```
return "#{self.procedure.name}"

```

13. end
14. 
15. def type\_name
16. 

```
return "#{self.type.name}"

```

17. end
18. 
19. def type\_field
20. 

```
return "#{self.type.field}"

```

21. end
22. 
23. def destination\_name
24. 

```
return "#{self.destination.name}"

```

25. end

Thus, I defined the additional fields which I would like ferret to  
index. It was doing this perfectly until recently, and I have tried  
rebuilding the indexes of the above models and tried various other  
small edits, but nothing has helped thus far.

Any ideas would be most appreciated. Thanks.  
Jon

---

<div class="post-metadata">

**Author:** ![jonathan\_stegall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jonathan\_stegall](https://www.ruby-forum.com/u/jonathan_stegall)\
**Post date:** [February 4, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/habtm-and-ferret/127953/2 "2008-02-04T22:58:19Z")

</div>

bump.
