Vails js Modelos não disponíveis nos controladores


0

Eu gerou controladores e modelos usando sails gerar.

Eu posso ver todos os modelos são carregados com console.log (velas)

enter image description here

Eu tentei duas maneiras de retorno não pode encontrar erro no model.find () TypeError: Não é possível ler a propriedade 'find' de undefined

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)

  },

};
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.