Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Delete All Records


Go to End


4 Posts   1928 Views

Avatar
Bagzli

Community Member, 71 Posts

15 March 2015 at 11:08am

Hi,

I am trying to figure out how to clean a table of all records. I understand silverstripe does version control and for that reason it won't delete the records but it will make them not active. What I am looking to do is completely wipe the DataObject, meaning no versions no nothing. Is this possible with silverstripe framework or do I have to do a custom DELETE FROM query? Also if I have a DataObject called Player and I do DELETE FROM Player, will this somehow create a problem? Is there a second table somewhere that depends on the records in this one? In order to completely wipe DataObject Player, do I have to delete more than one table?

Not sure if this would be relevant, but I need to continue adding new records after the table has been wiped, so I'm not trying to destroy it.

Avatar
Bagzli

Community Member, 71 Posts

20 March 2015 at 11:20am

I'm not sure if bumping is allowed, if not please let me know.

Avatar
Pyromanik

Community Member, 419 Posts

25 March 2015 at 10:59am

Edited: 25/03/2015 11:07am

This depends on several things.

One (the most important) being whether or not your object is versioned at all.
Unless you explicitly set Player to be versioned, then upon removal, it will be gone.

If you wish to wipe the very existence of a versioned object (always) upon delete, then probably onBeforeDelete() and manually removing the entries form the appropriate table is best.

By default only SiteTree is versioned. It is put in 2 stages, draft (stage) and live (live). You can see the applicable tables in the database. When you remove a page, it is in fact removed from it's table as DELETE FROM SiteTree would give. The ability to restore comes from the Versioned extension, and the existence of records in the other SiteTree tables.

http://doc.silverstripe.org/en/developer_guides/model/versioning

The other caveat is if you're removing from a relation list.
You can remove:

  1. the relation (the link between two records)
  2. the record (and thus the relationship with it)

Avatar
Bagzli

Community Member, 71 Posts

25 March 2015 at 12:32pm

ok so basically since this is a DataObject I can do Player->delete(); and the record will be permanently gone.

Thanks for your help.