balderdashy / balderdashy/sails
findOne blueprint only allows querying by primaryKey
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**Node version**: 12.16.1
**Sails version** _(sails)_: 1.2.4
**ORM hook version** _(sails-hook-orm)_: 2.1.1
**Sockets hook version** _(sails-hook-sockets)_: 2.0.0
**Grunt hook version** _(sails-hook-grunt)_: 4.0.0
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_: sails-mssql@2.1.2
In a custom parseBlueprintOptions I'm trying to add in additional fields to check. Some are business logic some are authorization based.
My problem occurs because in the findOne blueprint the where clause is stripped to just the primaryKey.
Example, I add {archived: false} to the queryOptions where clause, so that I have {where: {id: 1234, archived: false}}. This will make sure that if a resource is archived that it no longer shows up in queries. This works as expected in the "find" blueprint, but for "findOne" only the "id" is used during query, so archived resources show up in my query :(.
**Can we remove line 32 of the findOne action blueprint?**
https://github.com/balderdashy/sails/blob/master/lib/hooks/blueprints/actions/findOne.js#L32
Contributor guide
Research direction
Read lib/hooks/blueprints/actions/findOne.js at the linked line and trace how the where clause is reduced before the query. Reproduce the reported case with id: 1234 and archived: false, then verify that findOne respects both conditions as find does.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100