strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.22k stars 1.2k forks source link

Querying with relation throwing parse integer error #1982

Closed SaiNageswarS closed 8 years ago

SaiNageswarS commented 8 years ago

I have two relations pricelist and product as follows :


{
  "name": "PriceList",
  "base": "PersistedModel",
  "idInjection": true,
  "indexes": {
    "ean_vendor_index": {
      "keys": {
        "EAN": 1,
        "vendorId": 1
      }
    },
    "options": {
      "unique": true
    }
  },
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "vendorId": {
      "type": "number",
      "required": true
    },
    "EAN": {
      "type": "number",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "product": {
      "type": "belongsTo",
      "model": "Product",
      "foreignKey": "EAN"
    },
    "vendor": {
      "type": "belongsTo",
      "model": "Vendor",
      "foreignKey": "vendorId"
    }
  },
  "acls": [],
  "methods": {}
}

{
  "name": "Product",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "EAN": {
      "type": "number",
      "required": true,
      "index": {
        "unique": true
      }
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

A URL request as :

http://localhost/api/PriceLists/findOne?filter={%22where%22:{%22vendorId%22:1,%22EAN%22:%225185657766231%22},%22include%22:[%22product%22]}

gives following error :

{"error":{"name":"error","status":500,"message":"value \"5185657766231\" is out of range for type integer","length":100,"severity":"ERROR","code":"22003","file":"numutils.c","line":"75","routine":"pg_atoi","stack":"error: value \"5185657766231\" is out of range for type integer\n at Connection.parseE (/home/sainageswar/MyProjects/ideal-lamp-server/node_modules/pg/lib/connection.js:539:11)\n at Connection.parseMessage (/home/sainageswar/MyProjects/ideal-lamp-server/node_modules/pg/lib/connection.js:366:17)\n at Socket. (/home/sainageswar/MyProjects/ideal-lamp-server/node_modules/pg/lib/connection.js:105:22)\n at emitOne (events.js:77:13)\n at Socket.emit (events.js:169:7)\n at readableAddChunk (_stream_readable.js:146:16)\n at Socket.Readable.push (_stream_readable.js:110:10)\n at TCP.onread (net.js:523:20)"}}

gunjpan commented 8 years ago

@SaiNageswarS : Hi Sai, I tried to reproduce the issue above. For that, I created a sandbox application and ran the same query on it, and it was working fine on my side. PTAL at this Sandbox.

One question: Are you using memory as a database? if not, please provide with a sample repo so that I can reproduce it. Hope that helps!

Neil-UWA commented 8 years ago

the value you provide is out of the range with the default type in your database, you probably should set the value type more specific, like

"postgresql": {
    "dataType": xxx
}
SaiNageswarS commented 8 years ago

@gunjpan @Neil-UWA Thank you for quick response.

@Neil-UWA I tried your idea, however, I m still getting exception.

@gunjpan I'm using postgres database. Following is link to repo : https://bitbucket.org/SaiNageswar/ideal-lamp

The repo has migrations folder under server. It has table creation scripts and sample data as well. Thanks a lot for help...

gunjpan commented 8 years ago

@SaiNageswarS : Thanks for providing the repo, I will look into it at my earliest :)

SaiNageswarS commented 8 years ago

@gunjpan Thanks... Actually @Neil-UWA suggestion worked.. While trying the suggestion, I used dataType as datatype.

Thanks a lot

gunjpan commented 8 years ago

@SaiNageswarS: glad it worked out. Thank you for closing :)