# Field names, aliases and finders

**URL:** <https://www.ruby-forum.com/t/field-names-aliases-and-finders/128370>\
**Category:** Rails\
**Created:** [February 7, 2008, 3:35am UTC](https://www.ruby-forum.com/t/field-names-aliases-and-finders/128370 "2008-02-07T03:35:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [February 7, 2008, 3:35am UTC](https://www.ruby-forum.com/t/field-names-aliases-and-finders/128370/1 "2008-02-07T03:35:34Z")

</div>

I can not seem to make finders work with aliases. My goal is to map  
some fugly field names to nice field names and have the finders work  
with the nice field names.

An example.

class Users \< ActiveRecord::Base  
alias :password :UserPWD  
end

This doesn’t seem to work because obviously the object doesn’t have a  
method called UserPWD.

What is the best way (short of a view) to create field name mappings?  
Is it possible to make it so that my finders also work with the new  
names so I can type Users.find\_by\_password rather then  
Users.find\_by\_UserPWD

Thanks.

---

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [February 12, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/field-names-aliases-and-finders/128370/2 "2008-02-12T23:27:23Z")

</div>

On Feb 6, 2008 8:35 PM, Tim U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I can not seem to make finders work with aliases. My goal is to map  
> some fugly field names to nice field names and have the finders work  
> with the nice field names.
> 
> An example.
> 
> class Users \< ActiveRecord::Base  
> alias :password :UserPWD  
> end

def password  
UserPWD  
end

> This doesn’t seem to work because obviously the object doesn’t have a  
> method called UserPWD.
> 
> What is the best way (short of a view) to create field name mappings?  
> Is it possible to make it so that my finders also work with the new  
> names so I can type Users.find\_by\_password rather then

Model names are typically singular.

> Users.find\_by\_UserPWD

def self.find\_by\_password( p )  
self.find\_by\_UserPWD p  
end

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
