James A Mohler
James A Mohler

Reputation: 11120

Entity refuses to delete

Entity refuses to Delete

 ...
    var ormPref = EntityLoad("Pref", {PrefGroup = arguments.prefGroup, Pref = arguments.pref});

writedump(ormPref);

if (isnull(ormPref))    { return false; }
if (ArrayLen(ormPref) == 0) { return false; }

for (var i = 1; i <= ArrayLen(ormPref); i++)    {
    EntityDelete(ormPref[i]);
    EntitySave(ormPref[i]); 

    writeoutput("deleted");
    }

ORMFlush();

writedump(ormPref);

...

The entity's definition is:

<cfcomponent persistent="true">
<cfproperty name="PrefID" fieldtype="id" generator="identity">
<cfproperty name="PrefGroup">
<cfproperty name="Pref">
<cfproperty name="Value">
<cfproperty name="modifyBy">
<cfproperty name="modifyDate"   generated="always">
<cfproperty name="createBy"     update="false">
<cfproperty name="createDate"   update="false" generated="always">
</cfcomponent>  

Update

It turns out that it was deleted, an some other code later noted it was missing and added it back in. So the the function did work as it should

Upvotes: 1

Views: 73

Answers (2)

James A Mohler
James A Mohler

Reputation: 11120

Check to make sure something else is not adding the data back in

Upvotes: 1

scrittler
scrittler

Reputation: 1121

Those deletes should be wrapped in a transaction block. Also, try deleting starting from the end of the array (not the start). Would be helpful if you would post the exact error you're getting on delete too.

Upvotes: 2

Related Questions