Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataType: "decimal" gives a string through the api #101

Closed
jlvdh opened this issue Aug 6, 2015 · 7 comments
Closed

dataType: "decimal" gives a string through the api #101

jlvdh opened this issue Aug 6, 2015 · 7 comments
Assignees

Comments

@jlvdh
Copy link

jlvdh commented Aug 6, 2015

When using dataType: decimal the api seems to return a string instead of a number.

in model.json:

"property1": {
  "type": "number",
  "postgresql": {
    "dataType": "decimal"
  }
"property2": {
  "type": "number"
}

from the api:

"property1": "30.3",
 "property2": 4
@raymondfeng
Copy link
Contributor

Do you see it from REST or node?

@jlvdh
Copy link
Author

jlvdh commented Aug 6, 2015

from the loopback explorer

@raymondfeng
Copy link
Contributor

This is the behavior from the postgresql node.js driver - brianc/node-postgres#353. The main purpose is to avoid loss of decimal data.

@jlvdh
Copy link
Author

jlvdh commented Aug 6, 2015

Thanks, that's clarifying a lot.

However, I'm running in to trouble while using the validatesNumericalityOf when doing a put request changing another property.

validation:

Model.validatesNumericalityOf('property1', {int: false});

Request

PUT /api/model/4

{ "other_property": "other value" }

gives:

"message": "The `model` instance is not valid. Details: `property1` is not a number (value: \"3000\").",

@mirek
Copy link

mirek commented Oct 29, 2015

@jlvdh if you don't care about decimal precision or you can guarantee safe precision (21?) you can do something like https://github.com/mirek/node-pg-safe-numbers is doing, but it's global/intrusive on pg, so care must be taken (all other libraries using pg will also use new parser).

@FreakTheMighty
Copy link

This confused me as well. Also, it seems a little inconsistent. On a PUT I found that the response was a number. When listing the resource, however, it has been converted to a string.

@ssh24 ssh24 self-assigned this Jun 23, 2017
@ssh24 ssh24 added the apex label Jun 23, 2017
@ssh24
Copy link
Contributor

ssh24 commented Jun 23, 2017

Related to #58. Closing this issue. Feel free to reopen if needed.

@ssh24 ssh24 closed this as completed Jun 23, 2017
@ssh24 ssh24 added this to the Sprint 38 - Apex milestone Jun 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants