Mitul Pokiya
Mitul Pokiya

Reputation: 172

How to remove Duplicate items from siblings filter in Fluent Vapor 4?

I have a query in Fluent Vapor that applies siblings filters based on metaTagIds. Here's the code snippet:

let queryBuilder = Attraction.query(on: req.db)
if let metaTagIds = attractionSearch.metaTagIds, metaTagIds.count > 0 {
    queryBuilder.join(siblings: \.$metaTags)
    queryBuilder.filter(MetaTag.self, \.$id ~~ metaTagIds)
}

After applying these siblings filters, I want to remove duplicate values from the queryBuilder. How can I achieve this in Fluent Vapor?

Any help or guidance would be appreciated. Thank you!

Upvotes: 1

Views: 104

Answers (1)

0xTim
0xTim

Reputation: 5620

This is caused by the way SQL databases work and how joins work - essentially you'll get the row from each side of the join, even if the row on the left has already matched.

You have a number of solutions to solve this, but it's got to be mainly done at the application layer and filtering out the duplicates.

There was some discussion on the Vapor Discord here https://discord.com/channels/431917998102675485/684159753189982218/1241984160781045843

Upvotes: 2

Related Questions