Sails js模型在控制器中不可用


0

我已经使用sails generate生成了控制器和模型。

我可以看到所有模型都已加载console.log(sails)

在此处输入图片说明

我尝试了两种方法都可以在model.find()TypeError中返回错误:无法读取未定义的属性'find'

模型/ 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
    }
    //  ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦  ╦╔═╗╔═╗
    //  ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
    //  ╩  ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝


    //  ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
    //  ║╣ ║║║╠╩╗║╣  ║║╚═╗
    //  ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝


    //  ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
    //  ╠═╣╚═╗╚═╗║ ║║  ║╠═╣ ║ ║║ ║║║║╚═╗
    //  ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝

  },

};

控制器/ 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)

  },

};
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.