Miscellaneous
invokeWithTransaction()
Signature
Section titled “Signature”invokeWithTransaction() — returns any
Description
Section titled “Description”Runs the specified method within a single database transaction.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
method | string | yes | — | Model method to run. |
transaction | string | yes | 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 | yes | 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. |
Examples
Section titled “Examples”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)>