mysql - how to store instance methods name of a class in a column in sql database? -
mysql - how to store instance methods name of a class in a column in sql database? -
i want create column has nested hash structure.
structure of column:
column_name: company { production=> {watch=> "yes",pen =>"no",pencil => "yes"} quality => {life_test =>"yes", strong_test =>"yes", flexibility_test => "no"} }
here production, quality models , watch, pen, pencil, life_test,strong_test instance method of respective classes. each instance method boolean value view page. how accomplish structure.
this called serialization , pretty easy. following:
class < activerecord::base serialize :company, json end bar = something.new bar.company = { :production=> {:watch=> true,:pen => false, :pencil => false} :quality => {:life_test =>true, :strong_test =>true, :flexibility_test => false} } bar.save
if want more info go here: http://api.rubyonrails.org/classes/activerecord/base.html , read part on "saving arrays, hashes, , other non-mappable objects in text columns" create sure company column in database text column.
mysql ruby-on-rails
Comments
Post a Comment