Skip to content

Instantly share code, notes, and snippets.

@aquaibm
Created June 25, 2018 09:23
Show Gist options
  • Save aquaibm/59a8b7ed2c5b2e4908e687fd47172ba3 to your computer and use it in GitHub Desktop.
Save aquaibm/59a8b7ed2c5b2e4908e687fd47172ba3 to your computer and use it in GitHub Desktop.
UserTopicPivot
struct UserTopicPivot: SQLitePivot {
var id: Int?
var userID: Int
var topicID: Int
typealias Left = User
typealias Right = Topic
static let leftIDKey: LeftIDKey = \.userID
static let rightIDKey: RightIDKey = \.topicID
}
extension UserTopicPivot: Migration {
static func prepare(on connection: SQLiteConnection) -> Future<Void>{
return Database.create(self, on: connection, closure: { (builder) in
try addProperties(to: builder)
builder.reference(from: \.userID, to: \User.id)
builder.reference(from: \.topicID, to: \Topic.id)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment