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.
Duane M. (Guest)
on 2006-06-02 17: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!
Kevin O. (Guest)
on 2006-06-02 19:08
(Received via mailing list)
On Friday, June 02, 2006, at 3:37 PM, Duane M. wrote:
>
>Thanks!
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>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
Duane M. (Guest)
on 2006-06-02 20:33
Kevin O. 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.