Storing Array in Database

Hey all,

I’m storing an array of timestamps in a field in my database as an
array. When the items get saved, however, some minus signs are appended
to the text:

sample output:

  • 1151971200
  • 1152576000
  • 1153180800
  • 1153785600
  • 1154390400

Is this normal behavior? When I retrive the value out of the database
and .to_a, the three minus signs (—) are counted as the first member
of the array. This is not what I was wanting (obviously). How do you
compensate for that without needing to go there and actually stip it
out?

Thanks so much!
-LW

On Friday, June 23, 2006, at 5:33 PM, Luke W. wrote:

  • 1153180800
    -LW


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

You want to use ‘serialize’ for this…

http://rails.outertrack.com/class/ActiveRecord%3A%3ABase
and look for
“Saving arrays, hashes, and other non-mappable objects in text columns”

a bit down the page

_Kevin

Luke W. wrote:

Hey all,

I’m storing an array of timestamps in a field in my database as an
array. When the items get saved, however, some minus signs are appended
to the text:

sample output:

  • 1151971200
  • 1152576000
  • 1153180800
  • 1153785600
  • 1154390400

Is this normal behavior? When I retrive the value out of the database
and .to_a, the three minus signs (—) are counted as the first member
of the array. This is not what I was wanting (obviously). How do you
compensate for that without needing to go there and actually stip it
out?

Thanks so much!
-LW

That’s YAML notation for an array. If you are using “serialize :foo”
they should automatically be converted back into an array for you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs