Skip to content

Miscellaneous

invokeWithTransaction()

invokeWithTransaction() — returns any

Runs the specified method within a single database transaction.

NameTypeRequiredDefaultDescription
methodstringyesModel method to run.
transactionstringyescommitSet 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.
isolationstringyesread_committedIsolation 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)>