Siblings queries are pulling the pivot ID instead of the related object ID
Closed this issue · 2 comments
EricWVGG commented
I think I might have found a bug in retrieving Siblings.
layout (id: Int, name: String)
article (id: Int, title: String)
article_layout (id: Int, articleID: Int, layoutID: Int)
The database looks something like this:
//table layout:
{ id: 1, name: "layout 1" }
{ id: 2, name: "layout 2" }
//table article:
{ id: 1, title: "article 1" }
{ id: 2, title: "article 2" }
{ id: 3, title: "article 3" }
{ id: 4, title: "article 4" }
{ id: 5, title: "article 5" }
{ id: 6, title: "article 6" }
///table article_layout:
{ id: 1, layoutID: 1, articleID: 1 }
{ id: 2, layoutID: 2, articleID: 5 }
{ id: 3, layoutID: 2, articleID: 6 }
When I run the following for layout 2:
return try layout.siblingArticles.query(on: req).all().flatMap(to: PublicLayout.self) { articles in
print(articles)
}
I receive:
[
{ id: 2, title: "article 5" },
{ id: 3, title: "article 6" }
]
So, it's returning the IDs from the pivot table instead of from the Article table.
EricWVGG commented
I have uploaded a demo of this bug here: https://github.com/EricWVGG/fluent_git500
EricWVGG commented
Have confirmed that this is only happening in SQLite. Closing this issue and refiling there.