Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Deletion of items managed by a DataObjectManager

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1225 Views
  • adesweb
    Avatar
    Community Member
    39 Posts

    Deletion of items managed by a DataObjectManager Link to this post

    Hi there,

    I have a DataObjectManager for the agency website I am developing which associated many brands with a client. I have on the portfolio page a drop-down for brands, which uses DataObject::get to retrieve all Brands. However I have noticed that when removing a Brand under the CMS this does not remove it from the database, and hence it still appears in the drop-down.

    One solution would be to convert the Brand objects to extend page, so I could at least check for a ParentID, but you still have a problem with unnecessary database bloat with items in there which should be deleted.

    Is there a better way?

    Adrian

  • UncleCheese
    Avatar
    4085 Posts

    Re: Deletion of items managed by a DataObjectManager Link to this post

    Deleting a record from the DOM should result in its removal from the database. I can't imagine why it wouldn't be executing that delete. Is that true for all of the objects you manage with DOM?

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Deletion of items managed by a DataObjectManager Link to this post

    Further to this, the problem actually occurs when I delete a client page, without first going through and deleting the brands from that client i.e reduncant brand objects are left over. The following query seems to work:

    $brands = Dataobject::get("Brand","","Name Asc","RIGHT JOIN ClientPage ON Brand.ClientID = ClientPage.ID"

    Anyone know of a solution to all of the redundant data/columns in the database once you start to delete stuff without going into PHPMyadmin or similar?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Deletion of items managed by a DataObjectManager Link to this post

    You're expecting the deletion of a page to result in a cascade delete of objects related to it? It doesn't work that way. You haven't necessarily orphaned your Brand object by deleting the page that relates to it. The Brand record may get paired up with another ClientPage at some point. That relation is not one-to-one.

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Deletion of items managed by a DataObjectManager Link to this post

    Thanks for clarifying. The thing is though, the Brand object could never get paired up again, because there isn't the option to associate current objects with a new Client Page using the DMA? Maybe my OO/SQL isn't the best

  • UncleCheese
    Avatar
    4085 Posts

    Re: Deletion of items managed by a DataObjectManager Link to this post

    Then I would just use an onBeforeDelete() hook in your page class.

    public function onBeforeDelete()
    {
    parent::onBeforeDelete();
    $this->FieldToDelete()->delete();
    }

    1225 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.