balderdashy / balderdashy/sails

ORM does not handle 'length' attributes due to lodash _.each()

Open
#4,353 6 comments 0 reactions 0 assignees View on GitHub
inconsistency needs documentation resolved
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: 1.0.0
**Node version**: v9.3.0
**NPM version**: 5.6.0
**DB adapter name**: sails-mysql
**DB adapter version**: 1.0.0
**Operating system**: MacOS 10.13.4


Sails does not handle models containing an attribute named 'length' due to lodash `_.each()` considering the object "array-like" due to the presence of a length attribute.

See https://lodash.com/docs/4.17.5#forEach

The error produced in my case is as follows:

`AdapterError: Unexpected error from database adapter: key.split is not a function
`

occurring at

`node_modules/waterline-utils/lib/joins/detect-children-records.js:49
`

due to `_.each()` returning the `(0, undefined)` key/value due to the presence of the length attribute.

I suggest that line 47 needs to replace `_.each()` with `_.forIn()`.

This resolves my issues, although I note that I have not looked for other related issues.

Contributor guide

Open the contributing guide

Research direction

Start at node_modules/waterline-utils/lib/joins/detect-children-records.js, especially lines 47-49, and inspect how lodash iteration handles a model attribute named length. Reproduce the AdapterError and verify completion by confirming that the length attribute no longer produces the key.split error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.