I have two models, Bite
and Tag
. They have a many-to-many relationship to each other, so I've created a BiteTagPivot
for easy filtering, which returns siblings()
.
I have created two Bite
s, which share 3 of the same Tag
s with a fourth Tag
being unique to the second Bite
. eg:
"Bite1": {
"tags": ["my", "first", "bite"]
}
"Bite2" {
"tags": ["my", "first", "bite", "man"]
}
I then have a route set up to return Future<[Tag]>
:
func getBiteTagsHandler(_ req: Request) throws -> Future<[Tag]> {
return try req.parameter(Bite.self).flatMap(to: [Tag].self) { bite in
return try bite.tags.query(on: req).all()
}
}
When running this query, I get the following responses:
bites/1/tags
[
{
"id": 1,
"title": "my"
},
{
"id": 2,
"title": "first"
},
{
"id": 3,
"title": "bite"
}
]
bites/2/tags
[
{
"id": 4,
"title": "my"
},
{
"id": 5,
"title": "first"
},
{
"id": 6,
"title": "bite"
},
{
"id": 7,
"title": "man"
}
]
Even though there are only 4 tags in my database:
/tags
[
{
"id": 1,
"title": "my"
},
{
"id": 2,
"title": "first"
},
{
"id": 3,
"title": "bite"
},
{
"id": 4,
"title": "man"
}
]
The second bite has the IDs of the SQLitePivot, not the SQLiteModel being returned (a Tag
).
In comparison, the MySQL ORM returns ids 1
, 2
, 3
for the first Bite
, and 1
, 2
, 3
, 4
for the second Bite
. I would expect this to be the case for SQLite as well.