# Displaying mapped values from the database

**URL:** <https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736>\
**Category:** Rails\
**Created:** [April 2, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736 "2007-04-02T17:09:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drlelon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@drlelon](https://www.ruby-forum.com/u/drlelon)\
**Post date:** [April 2, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736/1 "2007-04-02T17:09:33Z")

</div>

Hi,

I have values in my database stored as integers:

1, 2, 3, 4, 5

When I retrieve and display these values in a List or Show, I want to  
map them to text such as:

Text1, Text2, Text3, Text4, Text5

What’s the easiest way to do this?

Thanks,

David

---

<div class="post-metadata">

**Author:** ![drlelon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@drlelon](https://www.ruby-forum.com/u/drlelon)\
**Post date:** [April 2, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736/2 "2007-04-02T17:12:44Z")

</div>

On Apr 2, 2007, at 5:09 PM, David L. wrote:

> What’s the easiest way to do this?

Why aren’t they Text\* already in the database?

– fxn

---

<div class="post-metadata">

**Author:** ![drlelon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@drlelon](https://www.ruby-forum.com/u/drlelon)\
**Post date:** [April 2, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736/3 "2007-04-02T17:28:09Z")

</div>

I want to optimize the data in the database for summarizing.

Xavier N. wrote:

> On Apr 2, 2007, at 5:09 PM, David L. wrote:
> 
> > What’s the easiest way to do this?
> 
> Why aren’t they Text\* already in the database?
> 
> – fxn

---

<div class="post-metadata">

**Author:** ![drlelon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@drlelon](https://www.ruby-forum.com/u/drlelon)\
**Post date:** [April 2, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736/4 "2007-04-02T18:10:50Z")

</div>

On Apr 2, 2007, at 5:28 PM, David L. wrote:

> I want to optimize the data in the database for summarizing.

Optimization, it is really worth the trouble? That corner of the  
appliccation now is not smooth.

Anyway, the getter cannot be redefined for that purpose because it is  
used by AR to read attributes to save them, and you need the  
conversion only towards the view. (Kernel.caller hacks notwithstanding.)

An ad-hoc getter would be OK:

def foo\_without\_database\_optimization  
“Text#{foo}”  
end

that one would be called in views instead of the real getter.

– fxn

---

<div class="post-metadata">

**Author:** ![drlelon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@drlelon](https://www.ruby-forum.com/u/drlelon)\
**Post date:** [April 3, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/displaying-mapped-values-from-the-database/102736/5 "2007-04-03T21:53:07Z")

</div>

You could perhaps consider ENUM column type:  
[http://dev.mysql.com/doc/refman/5.0/en/enum.html](http://dev.mysql.com/doc/refman/5.0/en/enum.html)

On Apr 2, 5:09 pm, David L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
