0

我试图让猫鼬使用这个钩子与sailsjs一起工作

https://github.com/mikermcneil/sails-hook-orm-mongoose

在我尝试填充之前工作正常,当我收到错误时

MissingSchemaError:尚未为模型注册架构

这是我的架构设置的示例。

var Schema = sails.mongoose.Schema;
module.exports = {
  schema: {
    product: {
      type: Schema.Types.ObjectId,
      ref: 'Product'
    },
    order: {
      type: Schema.Types.ObjectId,
      ref: 'Order'
    },
    qty: {
      type: Number,
      default: 1
    },
    image: {
      type: Schema.Types.ObjectId,
      ref: 'Image'
    },
    total: Number,
    custom_items: [{
      type: Schema.Types.ObjectId,
      ref: 'CustomLineItem'
    }],
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
      index: true
    },
    owner: {
      type: Schema.Types.ObjectId,
      ref: 'User',
      index: true
    }
  },

  /**
   * constructSchema()
   *
   * Note that this function must be synchronous!
   *
   * @param  {Dictionary} schemaDefinedAbove  [the raw schema defined above, or `{}` if no schema was provided]
   * @param  {SailsApp} sails                 [just in case you have globals disabled, this way you always have access to `sails`]
   * @return {MongooseSchema}
   */
  constructSchema: function(schemaDefinedAbove, sails) {
    // e.g. we might want to pass in a second argument to the schema constructor
    var lineItemSchema = new sails.mongoose.Schema(schemaDefinedAbove, {
      autoIndex: false,
      collection: 'lineitem'
    });
    return lineItemSchema;
  }
};
4

1 回答 1

4

发现这是因为我的 ref 需要小写

于 2016-06-05T08:39:32.907 回答