lib/active_remote/persistence.rb in active_remote-2.0.2 vs lib/active_remote/persistence.rb in active_remote-2.1.0.beta1

- old
+ new

@@ -74,12 +74,15 @@ # record was not deleted, it will have error messages indicating what went # wrong. Returns the frozen instance. # def delete raise ReadOnlyRemoteRecord if readonly? - execute(:delete, "guid" => read_attribute("guid")) + response = rpc.execute(:delete, scope_key_hash) + # TODO: add errors here so success? actually does something... + # add_errors(response) + return success? ? freeze : false end # Deletes the record from the service (the service determines if the # record is hard or soft deleted) and freezes this instance to indicate @@ -97,12 +100,15 @@ # be persisted). If the record was not deleted, it will have error # messages indicating what went wrong. Returns the frozen instance. # def destroy raise ReadOnlyRemoteRecord if readonly? - execute(:destroy, "guid" => read_attribute("guid")) + response = execute(:destroy, scope_key_hash) + # TODO: add errors here so success? actually does something... + # add_errors(response) + return success? ? freeze : false end # Destroys (hard deletes) the record from the service and freezes this # instance to indicate that no changes should be made (since they can't @@ -126,10 +132,14 @@ def instantiate(record) skip_dirty_tracking do assign_attributes(record) end + # TODO: figure out how to safely run after_find/search callbacks here + # currently, several functions use this code path, so an alternate path + # may need to be added + run_callbacks :initialize @new_record = false self end @@ -219,16 +229,16 @@ # def create run_callbacks :create do # Use the getter here so we get the type casting. new_attributes = attributes - new_attributes.delete("guid") + new_attributes.delete(primary_key.to_s) - execute(:create, new_attributes) + response = rpc.execute(:create, new_attributes) - assign_attributes(last_response.to_hash) - add_errors_from_response + assign_attributes(response.to_hash) + add_errors(response) @new_record = has_errors? success? end end @@ -249,15 +259,15 @@ def update(attribute_names = @attributes.keys) run_callbacks :update do # Use the getter here so we get the type casting. updated_attributes = attributes updated_attributes.slice!(*attribute_names) - updated_attributes.merge!("guid" => self[:guid]) + updated_attributes.merge!(scope_key_hash) - execute(:update, updated_attributes) + response = rpc.execute(:update, updated_attributes) - assign_attributes(last_response.to_hash) - add_errors_from_response + assign_attributes(response.to_hash) + add_errors(response) success? end end end