therubymug / keymaker

A multi-layer REST API Ruby wrapper for the neo4j graph database.
MIT License
62 stars 12 forks source link

On update, existing node values destroyed if not present in update attributes #9

Open alank64 opened 11 years ago

alank64 commented 11 years ago

When performing an update, due to Neo4j's REST API PUT request, the node values are not preserved if not present in the update values. Nothing we can do about that one, but my guess is that keymaker is attempting to insert all the property values of the class but given the code:

def process_attrs(attrs)
    attrs = attrs.symbolize_keys
    self.class.properties.delete_if{|p| p == :node_id}.each do |property|
      if property == :active_record_id
        process_attr(property, attrs[:id].present? ? attrs[:id] : attrs[:active_record_id])
      else
        process_attr(property, attrs[property])
      end
    end
  end

it would set the property to nil if not present in the attrs passed (process_attr(property, attrs[property])). Therefore probably a change to the following:

def process_attrs(attrs)
    attrs = attrs.symbolize_keys
    self.class.properties.delete_if{|p| p == :node_id}.each do |property|
      if property == :active_record_id
        process_attr(property, attrs[:id].present? ? attrs[:id] : attrs[:active_record_id])
      else
        if attrs[property]
          process_attr(property, attrs[property])
        end
      end
    end
  end

this at least inserts current values and replaces current values defined in the passed attrs.