EntityMerge()
Attaches the given entity to the current ORM session. Returns a new persistent instance.
EntityMerge( entity=any );
Returns: any
| Argument | Description |
|---|---|
|
entity
any,
required
|
edit
The entity that must be attached to the ORM session. |
Usage Notes
editentityMerge() copies the state of a detached entity onto a persistent instance in the current session and returns that persistent instance. Always use the returned object — the original detached entity is not modified.
A common use case is reattaching an entity after ORMClearSession() or across requests.
See ORM - Sessions and Transactions for details on entity lifecycle states.
Examples
edit// Detach all entities, then reattach one
user = entityLoadByPK( "User", 42 );
ormClearSession();
// user is now detached — merge it back
merged = entityMerge( user );
// use 'merged', not 'user' — merged is the persistent instance
merged.setName( "Updated" );
ormFlush();
See also
- ORM
- ORM - Sessions and Transactions
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)