Hi,
I’m trying to create a many to many relationship with additional variables but can not find any examples.
I have User and Group objects and want to create if a user has either view or write privileges for groups.
here is my pivot class definition:
import FluentPostgreSQL
import Foundationfinal class UserGroupPivot: PostgreSQLUUIDPivot { var id: UUID? var canRead: Bool var canWrite: Bool var userID: User.ID var groupID: Group.ID typealias Left = User typealias Right = Group static let leftIDKey: LeftIDKey = \.userID static let rightIDKey: RightIDKey = \.groupID init (_ user: User, _ group: Group) throws { self .userID = try user.requireID() self .groupID = try group.requireID() self .canRead = false self .canWrite = false } init (_ user: User, _ group: Group, canRead: Bool, canWrite: Bool) throws { self .userID = try user.requireID() self .groupID = try group.requireID() self .canRead = canRead self .canWrite = canWrite } } extension UserGroupPivot: Migration {} extension UserGroupPivot: ModifiablePivot {}
I can see in the tables that the extra variables are created, but I don’t know how to populate these data.
How can I do a CRUD operation also how to know if a user can write to a group.
Thanks in advance