I am trying to do 2 joins to the same parent table on two different columns. Is this even possible? What I have:
func allItemsHandler(_ req: Request) throws -> Future<View> {
let templateName = "\(_itemsName)All"
let title = _itemPublicName
return try MemoEntity.query(on: req)
.join(field: \Asset.id, to: \.imageID)
.alsoDecode(Asset.self)
// This does not work
// .join(field: \Asset.id, to: \.soundID)
// .alsoDecode(Asset.self)
.all()
.flatMap(to: View.self) { data in
let items: [AllMemoEntityContext] = data.map { (arg) in
let (memoEntity, image) = arg
// let ((memoEntity, image), sound) = arg
return AllMemoEntityContext(item: memoEntity,
image: image,
sound: nil)
}
let context = AllMemoEntitiesContext(
title: title,
items: items)
return try req.leaf().render(templateName, context)
}
}
MemoEntity has two foreign keys to Asset using imageID and soundID columns. The above works fine for getting the image joined in but I cannot get the sound joined in. If I add the commented lines I get
[ ERROR ] SQLiteError.error: ambiguous column name: main.assets.id (SQLiteQuery.swift:91)
Any hints?