Method: SimpleRecord::ActiveSdb::Base#reload_attributes

Defined in:
lib/simple_record/active_sdb.rb

#reload_attributes(*attrs_list) ⇒ Object

Reload a set of attributes from SDB. Adds the loaded list to in-memory data. attrs_list is an array or comma separated list of attributes names. Returns a hash of loaded attributes.

This is not the best method to get a bunch of attributes because a web service call is being performed for every attribute.

item = Client.find_by_name('Cat')
item.reload_attributes('toys', 'name')   #=> {"name"=>["Cat"], "toys"=>["Jons socks", "clew", "mice"]}


773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'lib/simple_record/active_sdb.rb', line 773

def reload_attributes(*attrs_list)
    raise_on_id_absence
    attrs_list = attrs_list.flatten.map { |attribute| attribute.to_s }
    attrs_list.delete('id')
    result     = {}
    attrs_list.flatten.uniq.each do |attribute|
        attribute = attribute.to_s
        values    = connection.get_attributes(domain, id, attribute)[:attributes][attribute]
        unless values.blank?
            @attributes[attribute] = result[attribute] = values
        else
            @attributes.delete(attribute)
        end
    end
    mark_as_old
    result
end