Method: SimpleRecord::ActiveSdb::Base#save2
- Defined in:
- lib/simple_record/active_sdb.rb
#save2(options = {}) ⇒ Object
Store in-memory attributes to SDB. Replaces the attributes values already stored at SDB by in-memory data. Returns a hash of stored attributes.
sandy = Client.new(:name => 'Sandy') #=> #<Client:0xb775a7a8 @attributes={"name"=>["Sandy"]}, @new_record=true>
sandy['toys'] = 'boys'
sandy.save
sandy['toys'] = 'patchwork'
sandy.save
sandy['toys'] = 'kids'
sandy.save
puts sandy.attributes.inspect #=> {"name"=>["Sandy"], "id"=>"b2832ce2-e461-11dc-b13c-001bfc466dd7", "toys"=>["kids"]}
sandy.reload #=> {"name"=>["Sandy"], "id"=>"b2832ce2-e461-11dc-b13c-001bfc466dd7", "toys"=>["kids"]}
Options:
- :except => Array of attributes to NOT save
compare to put method
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
# File 'lib/simple_record/active_sdb.rb', line 859 def save2(={}) [:create_domain] = true if [:create_domain].nil? pre_save2 atts_to_save = @attributes.dup #puts 'atts_to_save=' + atts_to_save.inspect #options = params.first.is_a?(Hash) ? params.pop : {} if [:except] [:except].each do |e| atts_to_save.delete(e).inspect end end if [:dirty] # Only used in simple_record right now # only save if the attribute is dirty dirty_atts = [:dirty_atts] atts_to_save.delete_if { |key, value| !dirty_atts.has_key?(key) } end dom = [:domain] || domain #puts 'atts_to_save2=' + atts_to_save.inspect connection.put_attributes(dom, id, atts_to_save, :replace, ) apres_save2 @attributes end |