# Can you alias fields in acts\_as\_ferret?

**URL:** <https://www.ruby-forum.com/t/can-you-alias-fields-in-acts-as-ferret/116624>\
**Category:** Ferret\
**Created:** [October 8, 2007, 4:30am UTC](https://www.ruby-forum.com/t/can-you-alias-fields-in-acts-as-ferret/116624 "2007-10-08T04:30:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chase](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@chase](https://www.ruby-forum.com/u/chase)\
**Post date:** [October 8, 2007, 4:30am UTC](https://www.ruby-forum.com/t/can-you-alias-fields-in-acts-as-ferret/116624/1 "2007-10-08T04:30:12Z")

</div>

Is there any way to set a field name that is different than the method  
name used to populate it?

My example:

In Rails, I’m using acts\_as\_ferret on a Article model that has\_many  
Authors. I want to be able to index authors’ names with each article.  
Since @article.authors yields an array of Author objects (and not an  
indexable string), I’ve created this method in my Article model:

def authors\_aaf  
@authors.collect {|a| a.name }.to\_sentence  
end

I call it “authors\_aaf” because “authors” would cause a conflict. But I  
want my field name to be “authors”, because that makes the most sense.  
(Users shouldn’t have to type “authors\_aaf:Joe” to search by author.)

Any idea how this can/should be done?

---

<div class="post-metadata">

**Author:** ![chase](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@chase](https://www.ruby-forum.com/u/chase)\
**Post date:** [October 8, 2007, 1:11pm UTC](https://www.ruby-forum.com/t/can-you-alias-fields-in-acts-as-ferret/116624/2 "2007-10-08T13:11:53Z")

</div>

On Mon, Oct 08, 2007 at 04:30:12AM +0200, Chase DuBois wrote:

> def authors\_aaf  
> @authors.collect {|a| a.name }.to\_sentence  
> end
> 
> I call it “authors\_aaf” because “authors” would cause a conflict. But I  
> want my field name to be “authors”, because that makes the most sense.  
> (Users shouldn’t have to type “authors\_aaf:Joe” to search by author.)
> 
> Any idea how this can/should be done?

You could pass the query through a de-aliasing helper method - something  
that does query.gsub!(/authors:/, ‘authors\_aaf:’) - before handing off  
the  
query string to ferret.

-Chris
