|
FoxDataObjects |
Object-Relational Mapping Tool for Visual FoxPro® |
|
|
DeleteObject Method |
||
|---|---|---|
|
Deletes all records for a given object instance.
|
|||||
|
Parameters |
|||||
|
|||||
|
Return Value |
|||||
|
|||||
|
Remarks |
|||||
|
This method tries to remove a persistent object instance from the database and returns True (.T.) if succeeds or False (.F.) if the object instance can not be removed. If Session.AutoTransactions is set to True (.T.), then Session.DeleteObject will start a new transaction if no one is active. First, the OnDelete event procedure on the object is fired (if such procedure is coded on the class). In case this event procedure returns False (.F.) the operation is cancelled and the transaction is rolled back. Session.DeleteObject then deletes object instances for owned references and owned collections in a recursive way, it is: all referenced objects are deleted using the same procedure. The persistence engine clears all references to this object from other persisted object instances in the database. If some object reference pointing to the object to be deleted, is marked as Mandatory (see the Schema Manager mapping guide), then, the process is canceled and the transaction is rolled back. After that, the record/s for the object instance is/are deleted from the database. If everything is right, the OnDeleteBeforeGarbageCollection event procedure on the object is fired (if the event is coded on the class) and the garbage collection services removes any horphan object instance whose Parent_ID column can not be left unspecified (see Schema Manager). Finally, the AfterDeleted event procedure on the object is fired (if such procedure is coded on the class). Any failure in between all these steps, causes this method to roll back the transaction and to return a False (.F.) value. The Errors collection keeps all the errors messages logged in the process. If everything is right and the active transaction was started by this method call, then it commits the transaction and returns True (.T.).
|
|||||
| Example | |||||
|
oOrder=oSession.GetObject("Order","Number=1428")
IF oSession.DeleteObject(oOrder) ? "Order 1428 deleted" ELSE ? oSession.Errors.Count, " errors while trying to delete order 1428" FOR EACH oError IN oSession.Errors.Item ? oError.FullMessage ENDFOR ENDIF
|
|||||
| The sample retrieves an object
instance from the database and then deletes it.
|
|||||
|
See Also |
|||||
| Session.GetObject method | Session.CreateObject method | |||||
| Applies to: Session object | |||||
|
Send feedback on this topic to RunAhead Technologies For Technical support and product issues please contact us at support@foxdataobjects.com or visit http://www.foxdataobjects.com |
Copyright (c) 2000-2005 RunAhead Technologies