Forum: Ruby on Rails What's the model pattern for just storing an array of ints?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A24e589de07cb769a71f28aead957a48?d=identicon&s=25 Duane Morin (Guest)
on 2006-06-02 15:37
Maybe this question is obvious, but I'm missing the answer.  I want one
of the fields in my model to be an array of int.  These are not indexes
into another model.  I'm cool with creating another database table if I
have to, but then do I need to do a join to access the data?  Or does
Ruby have some cool trick where I can translate my array of ints into a
String, store it in a single field, and then be smart enough that when I
pull it back out I can convert it back into an array so nobody's the
wiser?  (I'm sure I can do this and be kludgy about it, I'm wondering if
there's something already built in that might mean I can do it
invisibly).

Thanks!
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-06-02 17:08
(Received via mailing list)
On Friday, June 02, 2006, at 3:37 PM, Duane Morin wrote:
>
>Thanks!
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails

in your model definition, you can do this..

def model
 serialize :some_array
end

Just make sure the column in the database can hold the serialized
object.  Probably 'text' or bigger.

_Kevin
A24e589de07cb769a71f28aead957a48?d=identicon&s=25 Duane Morin (Guest)
on 2006-06-02 18:33
Kevin Olbrich wrote:
>  serialize :some_array

Perfect!  Thanks Kevin.  And now that I know the word to google for I
see many obvious examples, including in the documentation for
ActiveRecord itself :)
This topic is locked and can not be replied to.