balderdashy / balderdashy/sails

FindOne() does not honor multiple where()

Open
#6,830 6 comments 0 reactions 0 assignees View on GitHub
orm question resolved
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Node version**: v8.16.0
**Sails version** _(sails)_: 1.2.3
**ORM hook version** _(sails-hook-orm)_: 2.1.1
**Sockets hook version** _(sails-hook-sockets)_: 1.5.5
**Grunt hook version** _(sails-hook-grunt)_: 1.0.8
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_: 1.0.2


I am in the process of migrating to version 1 and their is a breaking change that I did not see on the migration documents. This used to work in the prior version.

Agreement.findOne()
.where({id: agreementId})
.where({locationId: employee.currentLocation.id})

Now this fails with

More than one matching record found for `.findOne()`:

I stepped through the adapter code and it ignores all .where() except the last where, which is an issue.

Contributor guide

Open the contributing guide

Research direction

Reproduce the chained Agreement.findOne().where({id: agreementId}).where({locationId: employee.currentLocation.id}) query using Node v8.16.0, Sails 1.2.3, sails-hook-orm 2.1.1, and the reported database adapter version. Start in the adapter code where the query criteria are assembled, as the report says only the last where is honored. Done means both predicates are applied and the multiple-match error no longer occurs when only one record satisfies them.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.