just realize...
in the case od 1st method:
everything is simple, but db grows.. but... you made some typo mistake
(eg Albama instead of Alabama) and what then.. repair entire table to
get the correct results? weird
2nd method:
I'm using it for a small enumeration lists (not hundreds/thousands items
- then is better to use db enumeratin methods, like countries table and
country_id column)
in app/model/some_model.rb
@@enum_list = %w( value1 value2 value3 )
# to use in erb templates for form.select() helper
def self.enum_list_for_select
@@enum_list.enum_with_index.collect{|k,v| [k,v]}
end
def enum_list_to_text
self.enum_list.nil? ? 'undefined' : @@enum_list[self.enum_list]
end
tom
Vipin wrote:
> in a database table if there is a field which has a certain set of
> fixed values. for example
> staus => {Single, Married, Divorced }
> OR
> state => {California, Albama, Olaska ...}
>
> so what should be preferred way out of the following for storing the
> values
>
> 1. Keep the field as "string(Rails)" VARCHAR(MySQL) itself ....and
> while showing the field just show the field value.
>
> 2. Keep the field internally as a code like {:california =>
> 01, :albama => 02, washington => 03 ....} but while showing the state
> show only the corresponding state.
>
> By using option 2, a certain disadvantage is extra computation time
> required to find out corresponding state name based on code when
> showing the state field to user. But an advantage could be in terms of
> smaller database. In my opinion, saving 01 as an integer could save
> significant space than storing "california" if number of records
> happen to be in tens of thousands .
>
> please suggest ??
>
> vipin
>
>
--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz
===============================================================================
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---