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.

Data Model Questions /

Listening to ManyMany change events


Reply


5 Posts   271 Views

Avatar
senorgeno

Community Member, 10 Posts

30 July 2014 at 5:59pm

Im wanting to create basic versioning of the Group changes for a Member. If someone gets added to a new group either programmatically or via the CMS I would like to version this.

There isn't an extend hook on ManyMany list add so I can't see a way of somehow 'listening' to the add() event on a manymany list. Perhaps subclassing ManyMany and Object::useCustom()?? (seems very hacky) Or should I create a pull request with the extend function included for this? I can see it being handy in many other cases..

Another solution I had was that given Many Many table aren't versionable, creating a Group_Member DO with 2 has many joins coming in form Member and Group and versioning this.

Thoughts, ideas?

Avatar
Fred C.

Community Member, 18 Posts

1 August 2014 at 3:55am

Do you need versioning with rollback, or just a journal of changes? The Versioned class is a DataExtension, so you won't be able to apply it to ManyManyList, which does not descend from DataObject. So it seems you'll either have to patch ManyManyList or its ancestors, or write your own Extension subclass.

Avatar
senorgeno

Community Member, 10 Posts

1 August 2014 at 2:14pm

I need a journal of changes. My idea of essentially replicating the Group_Member join table into a DataObject was a potential work around for ManyMany relations not being able to be versioned/journaled.

Ideally there would be a $this->extend() hook in ManyMany add(), then I could create an extension to work this in, however I'd prefer not to fork sapphire unless others deemed this reusable/a good idea.

Not sure what the protocol is on a change like this if I am not sure its best practice. Should I do a pull request? Then wait to hear feedback for core team?

Avatar
Willr

Forum Moderator, 5513 Posts

5 August 2014 at 9:30pm

Hi senorgeno,

Not sure what the protocol is on a change like this if I am not sure its best practice. Should I do a pull request? Then wait to hear feedback for core team?

In this situation, post to the Google dev group so that a correct course of action can be decided on (either an extension hook or someone finally get's sorted and builds an event system).

https://groups.google.com/forum/#!forum/silverstripe-dev

Avatar
swaiba

Forum Moderator, 1804 Posts

8 November 2014 at 12:22am

Hi senorgeno,

This contains my solution for logging relationship changes...

http://www.silverstripe.org/community/forums/general-questions/show/75365

As a side note this is the based for undo / redo in the system too - but because this is not handled with versioning.

Barry