balderdashy / balderdashy/sails

Population returning `null`, omiting attributes and changing attributes names after upgrading to sails 1.2.3 from 0.12

Open
#6,891 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

helpful info or workaround orm v0.12 v1.x
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Node version**: v12.13.0
**Sails version** _(sails)_: 1.2.3
**ORM hook version** _(sails-hook-orm)_: 2.1.1
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_: sails-postgresql@1.0.2


Hi,

After upgrading from sails 0.12 to 1 my models stopped populating some relationships and on some others the attributes names of the output objects are renamed to the letter `c`

The model attributes where changed to comply with the new validations and types, other than that the attributes are the same before and after the upgrade.

Models
```
// Facility.js
module.exports = {
schema: true,
attributes: {
....

provider: {
model: 'provider',
required: true,
columnName: 'group__c',
},

....
}
```

```
// Provider.js
module.exports = {
schema: true,
attributes: {
....

facilities: {
collection: 'facility',
via: 'provider'
},

....
}
```

Controller
```
// FacilityController.js
function find(req, res) {
Facility
.find()
.populate('provider')
.then(helpers.ifResultNotEmpty)
.then(f => res.json(f))
.catch(e => res.status(e.status).json(e))
}
```
Response before the upgrade:
```
[
{
"provider": {
"id": "ferferfeafre",
"name": "The name of the provider",
"createdAt": "2016-08-15T02:58:38.000Z",
"updatedAt": "2019-11-13T22:47:50.000Z",
"advisor": "42342fdsscsdcscsd",
"clientType": "The clientType",
"city": "Gotham",
"address": "1234 Evergreen Ave",
"state": "The state",
"postcode": "90210"
},
"id": "mcrioo34mro3r43",
"name": "The name of the facility",
"type": "The type of the facility",
"phone": "54 1234 1234",
"website": null,
"createdAt": "2016-08-15T04:17:48.000Z",
"updatedAt": "2019-11-13T22:47:50.000Z",
"racsId": 1234,
"careType": "The care type",
"clientType": "The client type",
"bedsHighCare": 96,
"bedsAgeingInPlace": 0,
"city": "Gotham",
"address": "234 Evergreen Ave",
"state": "The State",
"postcode": "90210",
"email": null,
"information": null
},
...
]
```

Response after the upgrade(note that apart from the population set to null, there are missing attributes, all of these missing attributes have the prop `columnName` attached to them):
```
[
{
"createdAt": "2016-08-15T07:18:09.000Z",
"updatedAt": "2019-01-23T13:01:26.000Z",
"id": "mcrioo34mro3r43",
"name": "The name of the facility",
"type": "The type of the facility",
"city": "Gotham",
"address": "1234 Evergreen Ave",
"state": "The State",
"postcode": "12345",
"phone": "43 3245 12222",
"website": null,
"provider": null
},
....
]
```

Another interesting behaviour in the upgraded version is, if i remove the `.populate()` call from the promise chain in the controller, the response objects shows the attributes with `columnName` back again.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the model definitions in Facility.js and Provider.js, then inspect FacilityController.js and reproduce the difference between populated and unpopulated queries. Compare the responses before and after population, focusing on relationships and attributes with columnName. Done means population returns the related provider and preserves the expected attribute names and values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, postgresql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.