Duane Morin
2006-Jun-02 13:38 UTC
[Rails] What''s the model pattern for just storing an array of ints?
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! -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jun-02 15:05 UTC
[Rails] What''s the model pattern for just storing an array of ints?
On Friday, June 02, 2006, at 3:37 PM, Duane Morin wrote:>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! > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsin 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 -- Posted with http://DevLists.com. Sign up and save your mailbox.
Duane Morin
2006-Jun-02 16:33 UTC
[Rails] Re: What''s the model pattern for just storing an array of in
Kevin Olbrich wrote:> serialize :some_arrayPerfect! Thanks Kevin. And now that I know the word to google for I see many obvious examples, including in the documentation for ActiveRecord itself :) -- Posted via http://www.ruby-forum.com/.