vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.32k stars 172 forks source link

Joined model doesn't use `deletedAt` property to exclude results #623

Closed jonny7 closed 4 years ago

jonny7 commented 5 years ago

Hi Tanner

Wrote this query last night:

UserOrganization.query(on: connection)
                .join(\Organization.id, to: \UserOrganization.organizationId)
                .filter(\UserOrganization.userId == id)
                .sort(\Organization.createdAt, .descending)
                .range(range)
                .alsoDecode(Organization.self)
                .all()

It returns:

SELECT * 
FROM "user_organization" 
    INNER JOIN "Organization" 
        ON "user_organization"."organizationId" = "Organization"."id" 
WHERE ("user_organization"."deletedAt" IS NULL OR "user_organization"."deletedAt" > ($1)) AND "user_organization"."userId" = ($2) 
ORDER BY "Organization"."createdAt" DESC 
LIMIT 1 OFFSET 5

Organization had to manually be added in .filter(\Organization.deletedAt == nil) to not return deleted organizations :)

tanner0101 commented 4 years ago

This should be fixed now, thanks!