Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add friends functionality to fix "beforeDelete" not being fired on pivot models #45

Closed
wants to merge 4 commits into from

Conversation

meysammahfouzi
Copy link
Contributor

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 table
4- 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 in afterSave() function residing in test/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 the beforeDelete method residing in test/models/FriendsPivot.php was not called. Manually remove the remained row from the table to clean things up.

@daftspunk
Copy link
Member

Thanks for this! This is a known limitation for a long time. There are relation events you can use to overcome this now.

@daftspunk daftspunk closed this Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants