0

After I upgrade to Sails v1, all the blueprint APIs that have the one-to-one relationship do not work when the FKs do not exist in the record. I am getting the following error message in the query response.

{
  "name": "AdapterError",
  "adapterMethodName": "find",
  "modelIdentity": "menu",
  "raw": {}
}

and error message on the debug log:

error: Sending 500 ("Server Error") response:
 AdapterError: Unexpected error from database adapter: Cannot read property 'undefined' of undefined
    at Object.findRecords (D:\vivacity\sails1\vivaapi\node_modules\sails\lib\hooks\blueprints\actions\find.js:30:4)
    at D:\vivacity\sails1\vivaapi\node_modules\sails\lib\router\bind.js:218:42
    at routeTargetFnWrapper (D:\vivacity\sails1\vivaapi\node_modules\sails\lib\router\bind.js:350:9)
    at Layer.handle [as handle_request] (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\layer.js:95:5)
    at next (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\layer.js:95:5)
    at D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\index.js:335:12)
    at next (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\index.js:275:10)
    at next (D:\vivacity\sails1\vivaapi\node_modules\express\lib\router\route.js:127:14)
    at D:\vivacity\sails1\vivaapi\api\policies\isAuthenticated.js:16:6
    at JwtStrategy.strategy.success (D:\vivacity\sails1\vivaapi\node_modules\passport\lib\middleware\authenticate.js:201:18)
    at verified (D:\vivacity\sails1\vivaapi\node_modules\passport-jwt\lib\strategy.js:102:33)
    at JwtStrategy._onJwtStrategyAuth [as _verify] (D:\vivacity\sails1\vivaapi\config\passport.js:21:10)
    at D:\vivacity\sails1\vivaapi\node_modules\passport-jwt\lib\strategy.js:110:26

The sample model that I defined is the following:

attributes: {    
"name": {
  type: "json"
},
"description": {
  type: "json"
},
"horizontalImageURL": {
  type: "string"
},
"verticalImageURL": {
  type: "string"
},
"currency": {
  type: "string",
  isIn: ["GBP", "EUR", "CNY"],
  defaultsTo: "GBP"
},
"price": {
  type: "number",
  defaultsTo: 0.00,
},
"menu": {
  model: "Menu",
  unique: true
},
"discount": {
  model: "Discount"
},
"image": {
  model: "Image"
},
"commission": {
  type: "number",
  defaultsTo: 0.00,
},
"commission_type": {
  type: "string",
  isIn: ['fixed-amount', 'percentage']
},
"stock": {
  type: 'number'
},
"paymentProvider": {
  type: 'string',
  isIn: ['wirecard', 'stripe', 'wechat']
},
"isReservationRequired": {
  type: 'boolean'
},
"maxParty": {
  type: 'number'
}}

I followed the example from http://next.sailsjs.com/documentation/concepts/models-and-orm/associations/one-to-one but still able to solve the issue. Any advice on solving this blueprint issue on Sails v1 will be great.

SzeLee Lai
  • 25
  • 1
  • 7

0 Answers0