Add friends functionality to fix "beforeDelete" not being fired on pivot models #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make sure you have the latest edge update. I am on build 427. Steps to reproduce the problem:
1- The Rainlab User plugin should be installed: https://octobercms.com/plugin/rainlab-user
2- Install the October Test plugin
3- In the October Test plugin, apply the migration version 1.0.4 to create the
october_test_friends
table4- From the top menu, select "Users"
5- Make sure there are at least two users available, "User1", "User2", if not, create them. We are going to make them friends!
6- In the list of users, click on User1
7- In the user preview page that opens, you should be able to see the newly added
Friends
tab, select it.8- In the
Friends
tab, click "Add new friend". A pop-op will open showing other users (it should include "User2")9- Click on "User2". The dialogue changes to "Related new friend data". Click "Add".
10- Now User2 should appear in the list of friends of User1 in Friends tab.
11- Check the database table
october_test_friends
. Two rows should have been added indicating that User1 is friends with User2 and User2 is friends with User1. The second row has been added inafterSave()
function residing intest/models/FriendsPivot.php
file.12- Remove the friendship. In the Friends tab, select User2 and click the "Remove" button. Again check the
october_test_friends
table. Only one of the rows has been removed while we expected both of them to be removed. That is because thebeforeDelete
method residing intest/models/FriendsPivot.php
was not called. Manually remove the remained row from the table to clean things up.