I am attempting to persist a range of Arrays to my SQLite database in Rails.

At this time, I have got an item that may hold this kind of Array, and instances seem to save quickly and easily. However, it's clearly not endured towards the database-- after i call functions on my small_Object.array in sights diverse from the one which the array is produced on, it arrives nil and does not work.

For instance:

class My_Object < ActiveRecord::Base
  attr_accessor :array

After I call My_Object.new(:array => [ [1, 2, 3], [4, 5, 6] ]), everything seems to operate correctly, however i can't access the :array property elsewhere, it simply works out nil.

Any ideas?

First produce a text column known as array inside your table. Then use [cde]:


Which will instantly serialize your array using YAML and instantly unpack it whenever you pull it back from the database.

You need to reconsider your design though. You will not have the ability to do anything whatsoever whatsoever using the serialized data within the database and particularly, you will not have the ability to utilize it in queries. The YAML is going to be just an opaque blob that adopts the database and returns out, the database will not have the ability to do other things by using it. If you are sure that the database won't ever may need to look inside class My_Object < ActiveRecord::Base serialize :array end then proceed and employ array, otherwise you will want to setup extra tables to keep your array data.