3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2123 Views |
-
"$this->delete()" won't delete Dataobject on all Stages

23 August 2010 at 4:02am Last edited: 23 August 2010 4:35am
Hi,
after update to 2.4.1 i can't delete Dataobjects on all Stages from my Frontend-Forms (it works in the admin). The entry is only deleted in the _Live-Table and keeps it in the _Versions-Table and Stage-Table.Member Decorator:
function extraStatics() {
return array(
'has_many' => array( // Einladungen
'Invitations' => 'Invitation'
),
…
}function removeInvitation($invitationID) {
$invitationID = (int) $invitationID;
// prevents access to invitations from other users
if( !$this->owner->Invitations()->containsIDs(array($invitationID))) return false;
if (!is_numeric($invitationID) || $invitationID < 1) return false;
$invitation = $this->owner->Invitations()->find("ID", $invitationID);
if (!$invitation) return false;
// unset from member list
$this->owner->Invitations()->remove($invitation);
// delete
$invitation->delete();
}Invitation:
class Invitation extends DataObject {
static $extensions = array(
"Versioned('Stage', 'Live')"
);…
}Do you know something?
Best Regards ,
Jörn -
Re: "$this->delete()" won't delete Dataobject on all Stages

23 August 2010 at 9:14am
Probably because $invitation is a single dataobject and delete() only deletes the object in question and not any of its staged components. I think the easiest way is to call the deleteFromStage() function on the object to delete from each.
http://api.silverstripe.org/2.4/sapphire/model/Versioned.html#methoddeleteFromStage
-
Re: "$this->delete()" won't delete Dataobject on all Stages

23 August 2010 at 9:49pm Last edited: 23 August 2010 9:50pm
Hi,
thanks$invitation->deleteFromStage("Live");
$invitation->deleteFromStage("Stage");
$invitation->delete();delete it on both stages but keeps the Versions.
i'm a little bit confused, because i looked in the docs http://api.silverstripe.org/2.4/sapphire/model/DataObject.html#methoddelete and read:
void delete( )
Delete this data object.
$this->onBeforeDelete() gets called. Note that in Versioned objects, both Stage and Live will be deleted.
i try also "DataObjcect::get("Invitation", … )->delete(); but it only removes the data from the _Live-Table.
Something is wrong. The Delete-Method or the Docs.
Jörn
-
Re: "$this->delete()" won't delete Dataobject on all Stages

10 September 2010 at 12:48am
I encountered this problem too. Can somebody help?
-
Re: "$this->delete()" won't delete Dataobject on all Stages

10 September 2010 at 4:12pm
delete it on both stages but keeps the Versions.
Yes it won't delete versions as delete() may imply you want to revert to it (versions is like a history). Not sure if the ORM has any functionality for that (eg try allVersions()) but you could always use good old plain Database queries!
DB::query("DELETE FROM Table_versions WHERE RecordID = '$invitation->ID'");
| 2123 Views | ||
|
Page:
1
|
Go to Top |



