我已经使用sails generate生成了控制器和模型。
我可以看到所有模型都已加载console.log(sails)
我尝试了两种方法都无法在模型上找到错误的返回方法。find() TypeError:无法读取未定义的属性“查找”
model / Categories.js
/**
* Categories.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
module.exports = {
attributes: {
name: {
type: 'string',
required: true,
allowNull: false,
maxLength: 2000,
columnType: 'longtext',
example: 'Computers',
},
description: {
type: 'string',
required: false,
allowNull: true,
maxLength: 65535,
columnType: 'longtext',
example: 'Computers are amazing!',
},
active: {
type: 'number',
description: '0 => inactive, 1 => active',
example: 1,
defaultsTo: 1
},
meta_title: {
type: 'string',
required: true,
maxLength: 60,
example: 'Shop Computers Iclicksee!',
},
meta_description: {
type: 'string',
required: true,
maxLength: 500,
example: 'Shop Computers Iclicksee!',
},
meta_keyword: {
type: 'string',
required: true,
maxLength: 500,
example: 'Shop Computers Iclicksee!',
},
image_url: {
type: 'string',
required: true,
maxLength: 5000,
example: 's3://bucket/image.jpg',
},
image: {
type: 'string',
required: true,
maxLength: 5000,
example: 's3://bucket/image.jpg',
},
parent_id: {
type: 'number',
allowNull: true,
description: 'null => no parent top level category, 1 => parent_id = 1',
example: 1
},
path_id: {
type: 'number',
allowNull: true,
description: '',
example: 1,
},
opencart_category_id: {
type: 'number',
allowNull: true,
description: '',
example: 1,
},
level: {
type: 'number',
allowNull: true,
description: '',
example: 1
},
column: {
type: 'number',
allowNull: true,
description: '',
example: 1
},
onTop: {
type: 'number',
allowNull: false,
description: '',
example: 1,
defaultsTo: 0
},
store_id: {
type: 'number',
allowNull: true,
description: '',
example: 1
},
layout_id: {
type: 'number',
allowNull: true,
description: '',
example: 1
},
filter_id: {
type: 'number',
allowNull: true,
description: '',
example: 1
},
sort_order: {
type: 'number',
allowNull: true,
description: '',
example: 1
},
force_update: {
type: 'number',
required : false,
description: '',
example: 1,
defaultsTo: 0
}
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
},
};
controllers / CategoriesController.js
/**
* CategoriesController
*
* @description :: Server-side actions for handling incoming requests.
* @help :: See https://sailsjs.com/docs/concepts/actions
*/
module.exports = {
nested: async function() {
var Categories = await Categories.find();
ResponseService.json(200, [], "Categories", Categories)
},
};