Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Or Group Serialization #449

Closed
jdmcd opened this issue Apr 15, 2018 · 0 comments
Closed

Incorrect Or Group Serialization #449

jdmcd opened this issue Apr 15, 2018 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jdmcd
Copy link
Member

jdmcd commented Apr 15, 2018

Executing this fluent command:

return try school
    .users
    .query(on: req)
    .filter(\.user_type_id == 1)
    .group(.or) { orGroup in
        try orGroup.filter(\.firstName ~~ "sally")
        try orGroup.filter(\.lastName ~~ "sally")
    }
    .sort(\.firstName, .ascending)
    .all()

Creates this SQL:

SELECT * FROM `users` WHERE (`users`.`school_id` = ? AND `users`.`user_type_id` = ? AND (`users`.`school_id` = ? OR `users`.`user_type_id` = ? OR `users`.`firstName` LIKE ? OR `users`.`lastName` LIKE ?)) ORDER BY `users`.`firstName` ASC ["integer8(1)", "integer8(1)", "integer8(1)", "integer8(1)", "string(\"%sally%\")", "string(\"%sally%\")"]

Note `users`.`school_id` = ? is incorrectly included at the root level of the query as well as inside of the or group. As a result, when I query for "sally" (and expect only one result back) all of the users within this school are returned. That part of the query should only be included at the root of the query.

@tanner0101 tanner0101 added the bug Something isn't working label Apr 20, 2018
@tanner0101 tanner0101 added this to the 3.0.0 milestone Apr 20, 2018
@tanner0101 tanner0101 self-assigned this Apr 20, 2018
@tanner0101 tanner0101 modified the milestones: 3.0.0, 3.0.0-rc.2.4.1 May 2, 2018
@tanner0101 tanner0101 modified the milestones: 3.0.0-rc.2.4.1, 3.0.0 May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants