Permalink
Browse files

do not perform update when no changes have been made to the propertie…

…s of a

model
closes issue #786
  • Loading branch information...
rip747 committed Aug 6, 2011
1 parent 0293d3e commit 3746de66ade2d2cce45c5eb476279b6c10e3e637
Showing with 23 additions and 0 deletions.
  1. +7 −0 wheels/model/crud.cfm
  2. +16 −0 wheels/tests/model/properties/timestamps.cfc
View
@@ -997,6 +997,13 @@
<cfargument name="reload" type="boolean" required="true">
<cfscript>
var loc = {};
+
+ // if no changes, no need to perform update
+ if(!hasChanged())
+ {
+ return true;
+ }
+
if (variables.wheels.class.timeStampingOnUpdate)
$timestampProperty(property=variables.wheels.class.timeStampOnUpdateProperty);
loc.sql = [];
@@ -0,0 +1,16 @@
+<cfcomponent extends="wheelsMapping.Test">
+
+ <cffunction name="test_updatedAt_does_not_change_when_no_changes_to_model">
+ <cftransaction>
+ <cfset post = model("Post").findOne()>
+ <cfset orgUpdatedAt = post.properties().updatedAt>
+ <cfset post.update()>
+ <cfset post.reload()>
+ <cfset newUpdatedAt = post.properties().updatedAt>
+ <cfset assert('orgUpdatedAt eq newUpdatedAt')>
+ <cftransaction action="rollback"/>
+ </cftransaction>
+ </cffunction>
+
+
+</cfcomponent>

0 comments on commit 3746de6

Please sign in to comment.