balderdashy / balderdashy/sails

Objects instantiated from es6 Classes throw error `E_INVALID_RECORD` in `create` method

Open
#4,355 7 comments 0 reactions 0 assignees View on GitHub
orm sails-disk what do you think?
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: 1.0.1
**Node version**: 8.11.1
**NPM version**: 5.6.0
**DB adapter name**: sails-disk
**DB adapter version**: 1.0.0-12
**Operating system**: Ubuntu 17.10


So, I have few helper database classes that I use to keep the sanctity of the database instanct.

Here's one such class

```
class BookingRequest {
constructor({person, date, slot, partner}){
this.person = person;
this.date = date;
this.slot = slot;
this.partner = partner;
}
}
```
And here's my data model

```
module.exports = {
tableName: 'reservations',
attributes: {
person: {
type: 'string',
required: true
},
date: {
type: 'number',
required: true
},
slot: {
type: 'string',
required: true
},
partner: {
model: 'user',
required: true
}
},
};
```
And here's how I putting it all together:

```
const doc = new BookingRequest(req.body);
const createdBooking = await Reservation.create(doc).fetch();
```
And this throws error:
```
Failed process the values set for the record
```
The error code is:: `E_INVALID_RECORD`

But here's an interesting thing, I made it work with this hack,
```
const doc = new BookingRequest(req.bdoy);
const createdBooking = await Reservation.create(JSON.parse(JSON.stringify(doc))).fetch();
```
Now, I can't understand why it doesn't work without the hack.

Contributor guide

Open the contributing guide

Research direction

Start at the Reservation.create entry point and reproduce the difference between passing the BookingRequest instance and the JSON-cloned object. Trace where the record values are validated and compare the resulting E_INVALID_RECORD details; done means the class-instance behavior has a confirmed, tested outcome or a clearly documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, 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.