Sails JS-水线ORM-MySQL.表自动生成 [英] Sails js - waterline orm - mysql. Tables autogeneration

查看:136
本文介绍了Sails JS-水线ORM-MySQL.表自动生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Sails中创建模型-水线时,数据库是自动生成的. 问题是我的主键是unsigned int(10),而外部键是int(11)(带符号).实际上,该关系仅存在于我的模型中,而不存在于db中. 下面是一个代码示例:

When I create my model in sails - waterline the db is autogenerated. The problem is that my primary keys are unsigned int(10) and the external keys are int(11) (with sign). In fact the relationship is only in my models and not in db. A code example is the following:

// A user may only have a single pet
var User = Waterline.Collection.extend({

identity: 'user',
connection: 'local-postgresql',

attributes: {
  firstName: 'string',
  lastName: 'string',

// Add a reference to Pet
  pet: {
    model: 'pet'
  }
 }
});

var Pet = Waterline.Collection.extend({

 identity: 'pet',
 connection: 'local-postgresql',

 attributes: {
  breed: 'string',
  type: 'string',
  name: 'string',

   // Add a reference to User
   user: {
     model: 'user'
   }
 }
});

在此示例中,我的数据库是通过以下方式生成的: pet"id"(在pet表中)是一个自动递增的主键,无符号int(10) 而"pet"(在用户表中是指向pet id的外键)是int(11)(带符号int).有解决这个问题的办法吗?谢谢

In this example my database is generated in the following way: pet "id" (in pet table) is an autoincrement primary key unsigned int(10) and "pet" (in user table that is an external key pointing to pet id) is a int(11) (signed int). There is a solution to that problem? thanks

推荐答案

sails-postgresql适配器尚未在数据库本身中创建外键关系.这不是不正确,并且不会影响您使用风帆/水线的方式.一切都会正常,这只是尚未实现的优化.

The sails-postgresql adapter does not yet create foreign key relationships in the database itself. This is not incorrect and doesn't affect how you use sails/waterline. Everything will work fine, this is just an optimization that hasn't been implemented yet.

如果您想在此分享您的想法,则有一个公开的问题: https://github.com/balderdashy/sails-postgresql/issues/123

There's an open issue if you'd like to share your thoughts there: https://github.com/balderdashy/sails-postgresql/issues/123

这篇关于Sails JS-水线ORM-MySQL.表自动生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆