But, if you knew that you'd never want to do any SQL actions on that
array (it was just extra data attached to that record), wouldn't it
execute faster if you just save it as a string? And as far as being
clean, I'd think that not creating a table you didn't need was pretty
clean, too.

(I ask, not because I am convinced that serializing the array is
better, but because I keep wrestling with this every time it comes
up.)

On Sun, Jan 8, 2012 at 7:17 PM, Dave Aronson
<[email protected]> wrote:
> On Sun, Jan 8, 2012 at 19:02, Rodrigo Ruiz <[email protected]> wrote:
>
>> Hi, is there a way to save an array of float values to my database (for a
>> specific mode, for example User, so it stays like user.values = [0, 2, 54,
>> 3])?
>
> There are lots of ways.  For instance, if you really want to save it
> as an array, *and you don't need to do any math on it*, is to save it
> as a string, and turn it into an array again on reload.
>
> However, the *cleanest* (since the above is no doubt making many
> people lose their lunch), most *flexible*, and probably even most
> *easy to implement* (since Rails would as usual do a lot of the work
> for you), would be to make another table.  This table would include
> the ID(s) of the thing(s) the array is attached to, a positional index
> number (not to be confused with a database index), and the value.

-- 
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.

Reply via email to