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.

Data Model Questions /

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

Listening to ManyMany change events


Go to End


5 Posts   1811 Views

Avatar
gened

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 Condo

Community Member, 29 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
gened

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, 5523 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, 1899 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