EntitySave

Description

Saves or updates data of the object and all related objects to the database. This also saves all the related entities, which includes the entire graph. When entities are loaded, default constructors are called.ColdFusion automatically tries to find if a new record should be inserted or an existing record be updated for the given entity. If you set forceinsert=true, then ColdFusion tries to insert the entity as a new record.Calling this method may not run the insert or update SQL immediately. It is possible that various SQL statements are queued and then run as a batch for performance reasons. The SQL statements are run when the ORM session is flushed.

Category

ORM functions

Function Syntax

EntitySave(entity, [forceinsert])

Parameters

Parameter

Description

entity

Name of the entity that must be saved in the database.

forceinsert

If true, then ColdFusion always tries to insert the entity as a new record.

Example

To save an entity:

<cfset employee = createObject("Employee")> 
<cfset employee.setFirstName("Marcia")> 
<cfset employee.setlastName("Em")> 
<cfset EntitySave(employee)> 

To update an entity:

<cfset employee = EntityLoad('employee', 100, true)> 
<cfset employee.setLastName("Em")> 
<cfset EntitySave(employee)>