Sails 1.0没有主键的模型

问题描述 投票:1回答:2

我尝试使用新版本1.0并重构我的项目。我有一个问题,我现在不知道如何解决她。我的BD上的一些表没有主键,当我迁移到sails 1.0时,我有这个错误

在模型friends中:主键设置为id,但在模型上没有找到这样的属性。您必须在idapi/Friends.js中定义config/models.js属性。有关信息,请参阅http://sailsjs.com/upgrading#?changes-to-model-configuration

我可以使用没有主键的模型吗?

sails.js waterline
2个回答
1
投票

我有同样的问题,我用来更改主键:在文件config / model.js

attributes: {
      id: { 
         type: 'number', 
         autoIncrement: true, 
      },
    }

    and in the model api/any_model.js i used:

    tableName : 'table',
    attributes: {
      id: { 
       type: 'number',  
       columnName : 'column_you_like_to_be_a_primaryKEY',
       required : true
      },
    }

0
投票

我找到了解决方案。我禁用了钩子orm,现在我很开心=)创建文件.sailsrc并写入

{“hooks”:{“orm”:false}}

© www.soinside.com 2019 - 2024. All rights reserved.