Displaying mapped values from the database

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

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

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

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

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

On Apr 2, 5:09 pm, David L. [email protected]