lib/databasedotcom/sobject/sobject.rb in databasedotcom-1.0.8 vs lib/databasedotcom/sobject/sobject.rb in databasedotcom-1.0.9

- old
+ new

@@ -75,11 +75,12 @@ # c = Car.find_by_Color("Yellow") # c.Color = "Green" # c.save def save attr_hash = {} - self.class.description["fields"].select { |f| f["updateable"] }.collect { |f| f["name"] }.each { |attr| attr_hash[attr] = self.send(attr) } + selection_attr = self.Id.nil? ? "createable" : "updateable" + self.class.description["fields"].select { |f| f[selection_attr] }.collect { |f| f["name"] }.each { |attr| attr_hash[attr] = self.send(attr) } if self.Id.nil? self.client.create(self.class, attr_hash) else self.client.update(self.class, self.Id, attr_hash) @@ -133,11 +134,17 @@ self.description = self.client.describe_sobject(self.sobject_name) self.type_map = {} self.description["fields"].each do |field| name = field["name"] attr_accessor name.to_sym - self.type_map[name] = {:type => field["type"], :label => field["label"], :picklist_values => field["picklistValues"], :updateable? => field["updateable"]} + self.type_map[name] = { + :type => field["type"], + :label => field["label"], + :picklist_values => field["picklistValues"], + :updateable? => field["updateable"], + :createable? => field["createable"] + } end end # Returns the Force.com type of the attribute +attr_name+. Raises ArgumentError if attribute does not exist. # @@ -158,9 +165,14 @@ end # Returns true if the attribute +attr_name+ can be updated. Raises ArgumentError if attribute does not exist. def self.updateable?(attr_name) self.type_map_attr(attr_name, :updateable?) + end + + # Returns true if the attribute +attr_name+ can be created. Raises ArgumentError if attribute does not exist. + def self.createable?(attr_name) + self.type_map_attr(attr_name, :createable?) end # Delegates to Client.find with arguments +record_id+ and self # # client.materialize("Car") \ No newline at end of file