Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 52a563fe22
Fetching contributors…

Cannot retrieve contributors at this time

38 lines (27 sloc) 0.909 kb

DataColumns

Store multiple columns in serialized data column

Usage

Create in your model text column data

create_table <table_name> do |t|
  t.text :data
end

or

change_table <table_name> do |t|
  t.text :data
end

Examples

class Person < ActiveRecord::Base
  data_columns :icq, :skype
  data_columns :phone

  # type triggers standard conversions
  # no type - no conversions
  data_columns :some_time_ago, :type => :time, :default => 1.year.ago
  data_columns :x, :y, :z, :type => 'integer'

  validates_presence_of :phone
end

Person.create(:icq => '123456789', :skype => 'hello') # gives us error message as phone must be present :)

class Xman < ActiveRecord::Base
  # stores columns in a field called :cached_data instead of default :data
  data_columns :name, :field => :cached_data
end

Copyright © 2009 Ivan, released under the MIT license

Jump to Line
Something went wrong with that request. Please try again.