samedi 28 avril 2007
Rails : Sérialisation de Hash pour base de donnée
Par Christophe, samedi 28 avril 2007 à 01:11 :: Développement
J'ai découvert par hasard ceci :
Saving arrays, hashes, and other non-mappable objects in text columns
Active Record can serialize any object in text columns using YAML. To do so, you must specify this with a call to the class method serialize. This makes it possible to store arrays, hashes, and other non-mappable objects without doing any additional work. Example:
class User < ActiveRecord::Base
serialize :preferences
end
user = User.create(:preferences => { "background" => "black", "display" => "large" })
User.find(user.id).preferences # => { "background" => "black", "display" => "large" }
Une dé/sérialisation de données aussi aisée ? J'aime.
:: 2 commentaires ::
