2

I am using Sails alongside its Waterline ORM for PostgreSQL. I am having an issue with the defaultsTo parameter in model attribute definition.

Here is a part of my Model definition:

module.exports = {
  tableName: 'table',

  attributes: {
    [...]
    reach: {
      type: 'number',
      defaultsTo: 0,
    }
    [...]
  }
}

When using Model.create(), I get this console warning:

Warning: After transforming columnNames back to attribute names for model `model`,
 a record in the result has a value with an unexpected data type for property `reach`.
The corresponding attribute declares `type: 'number'` but instead
of that, the actual value is:
` ` `
'0'
` ` ` 

I have a bunch of number type attributes so this leads to a lot of warnings in my console.

At this point, I believe this is a waterline issue but do you have a workaround to avoid this warning?


Edit

My warning is only appearing for Postgres "BIGINT" column I am starting to undersand that JS cannot handle postgres BIGINT as number so it must be converted to string.

1 Answer 1

1

I found a way to avoid warning : set attribute a different way:

attributes: {
  [...]
  reach: {
    type: 'ref',
    columnType: 'bigint',
    isNumber: true,
    defaultsTo: 0
  },
  [...]
}
Sign up to request clarification or add additional context in comments.

3 Comments

I was having this problem too! Thank you I will try this!!
My thing is I need to create time fields, like the createdAt and updatedAt fields, is this the way you found to accomplish this?
I tried this, however the number is still coming back as string :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.