-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Cannot create siblings relation between same models #1932
Comments
Is MySQLPivot somehow a ModifiablePivot already? |
Don't think so. For attaching, I had to have it conform to |
The issue here is that in a same-Model ( extension User {
// the friends of the user
var friends: Siblings<User, User, UserFriendsPivot> {
return siblings(UserFriendsPivot.leftIDKey, UserFriendsPivot.rightIDKey)
}
// the users who have friended the user
var friendOf: Siblings<User, User, UserFriendsPivot> {
return siblings(UserFriendsPivot.rightIDKey, UserFriendsPivot.leftIDKey)
}
} The other same-Model consequence is that you will not be able to use the let pivot = try UserFriendsPivot(user, friend)
pivot.save(on: req) (There are other approaches to work around this, I just find these straightforward ways above the easiest to use. Specifying the sides and reversing the key positions to obtain the inverse relation are the important concepts.) |
@grundoon, thank you for your answer, I was able to compile the project w/ the code you provided. |
@LinusGeffarth Off the top of my head, I believe any method that accesses through the keyed user.friends.isAttached(friend, on: req)
^^^^^^^ |
Yeah, I've found that both methods do work. Thanks for your help! @grundoon |
I want to create a siblings relationship between two
User
models, for a sort-of "friend" feature, similar to Facebook.I created the
UserFriendsPivot
:I added the
friends
property toUser
:Now, I'm seeing the following error on the line with
return siblings()
:I tried to replace it with:
...without any luck.
I know that the two code snippets should work, because I straight-up copied them from another siblings relationship I built between
Event
andUser
that is working just fine.The only difference I'm seeing is that I'm trying to build a relationship between the same models.
Is this a Vapor bug, or just me doing something wrong here?
Environment
The text was updated successfully, but these errors were encountered: