Removing entity instances from the database
Bundle
interface’s delete method.Entity instance remove method
Mark an entity instance for removal from the database by using the remove method on the entity.
When the bundle is committed, the action
that PolicyCenter takes depends
on whether the entity is retireable. If the entity’s data model configuration
does not specify that the entity is Retireable,
the entity instance is deleted from the database. If the data model specifies
that the entity is Retireable,
PolicyCenter retires the entity
instance rather than deleting it. Additional actions of the remove method depend on the entity
type. Typically, remove
deletes owned child entity instances to which arrays in that instance
refer even if those entity types are Retireable.
Some entity types perform additional clean-up actions as part of their
remove implementation.
For example:
uses gw.transaction.Transaction
// Make a query of Address instances
var query = Query.make(Address)
// Query for addresses created today
query.compare(
DBFunction.DateFromTimestamp(query.getColumnRef("CreateTime")), Equals, DateUtil.currentDate())
for (address in query.select()) {
address = bundle.add(address)
address.remove()
}Bundle interface delete method
The Bundle
interface’s delete method
also provides the functionality to delete an entity instance from the
database. This method does not perform any additional actions to ensure
database integrity. The remove
method on some entity types does perform additional clean-up. For this
reason, if you must delete an entity instance, using the remove method on the entity instance
is strongly preferable to using the Bundle
interface’s delete method.
When the bundle is committed, the entity
instance is deleted from the database. If the entity’s data model configuration
declares the entity as Retireable,
the entity is not deleted, but is retired instead. The delete method removes only the
specified entity instance from the database, not linked entity instances.
See also
