balderdashy / balderdashy/sails

Certain or/and combinations failing in MySQL query builder

Open
#4,482 11 comments 0 reactions 0 assignees View on GitHub
bug orm try this out please
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: 1.0.2
**Node version**: 8.11.2
**NPM version**: 5.6.0
**DB adapter name**: sails-mysql
**DB adapter version**: 1.0.0
**Operating system**: OSX


A Query like this fails for every Model with MySQL. The Error happens after Stage 3; the statement compiler creates weird columns for this query:
`Model.find().where({a:1, or: [{b:2, c:3}]})`
-> `Error: Unexpected error from database adapter: ER_BAD_FIELD_ERROR: Unknown column '0' in 'where clause'`

### Other queries:
* works `Model.find().where({or: [{b:2, c:3}]})`
* works `Model.find().where({a:1, or: [{b:2, c:3}, {b:4, c:5}]})`
* **doesn't work:** `Model.find().where({a:1, or: [{b:2, c:3}]})`
* works `Model.find().where({and: [{b:2, c:3}]})`
* works `Model.find().where({a:1, and: [{b:2, c:3}, {b:4, c:5}]})`
* **doesn't work:** `Model.find().where({a:1, and: [{b:2, c:3}]})`

So there seems to be an error if there is a field and an `or`/`and` with only one element

Contributor guide

Open the contributing guide

Research direction

Reproduce the listed Model.find().where() cases against MySQL, then start at the Stage 3 statement compiler mentioned in the report. Compare the generated conditions for single-element `or` and `and` combinations with another field; done means these queries no longer produce an unexpected `0` column or a MySQL error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql, node.js
Domain
backend, database
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.