Runs the specified method within a single database transaction.
Name | Type | Required | Default | Description |
---|---|---|---|---|
method | string | Yes | Model method to run. | |
transaction | string | No | commit | Set this to commit to update the database when the save has completed, rollback to run all the database queries but not commit them, or none to skip transaction handling altogether. |
isolation | string | No | read_committed | Isolation level to be passed through to the cftransaction tag. See your CFML engine's documentation for more details about cftransaction's isolation attribute. |
invokeWithTransaction(method [, transaction, isolation ]) <!--- This is the method to be run inside a transaction ---> <cffunction name="transferFunds" returntype="boolean" output="false"> <cfargument name="personFrom"> <cfargument name="personTo"> <cfargument name="amount"> <cfif arguments.personFrom.withdraw(arguments.amount) and arguments.personTo.deposit(arguments.amount)> <cfreturn true> <cfelse> <cfreturn false> </cfif> </cffunction> <cfset david = model("Person").findOneByName("David")> <cfset mary = model("Person").findOneByName("Mary")> <cfset invokeWithTransaction(method="transferFunds", personFrom=david, personTo=mary, amount=100)>