postgresql - Sailsjs 模型对象不为 Postgresql 返回数据

标签 postgresql sails.js waterline

我的 Sailsjs config/adapter.js 中有以下内容:

module.exports.adapters = {
  'default': 'postgres',

  postgres : {
   module   : 'sails-postgresql',
   host     : 'xxx.compute-1.amazonaws.com',
   port     : 5432,
   user     : 'xxx',
   password : 'xxx',
   database : 'xxx',
   ssl      : true,
   schema   : true

  }
};

models/Movie.js 中:

 Movie = {

  attributes: {
    tableName: 'movies.movies',
    title: 'string',
    link: 'string'
  }

};

module.exports = Movie;

在我的 Controller 中:

Movie.query("SELECT * FROM movies.movies", function(err, movies) {
  console.log('movies', movies.rows);
});

movies.rows 确实返回正确的数据

但是:

  Movie.find({ title: 'Frozen' }, function(err, movies) {
    console.log('movies', movies)
  });

movies 返回一个EMPTY ARRAY

所以看起来所有连接都很好,因为原始查询工作得很好。

在设置 Movie.find() 或 models/Movie.js 时我是否做错了什么?

tableName属性不支持postgresql schema_name.table_name吗?

最佳答案

首先,您需要将 tableName 移出 attributes,因为它是一个类级别的属性。其次,sails-postgresql 使用 meta.schemaName 选项确实有一些(非常未记录的)模式支持:

Movie = {

  tableName: 'movies',
  meta: {
     schemaName: 'movie'
  },

  attributes: {
    title: 'string',
    link: 'string'
  }

};

module.exports = Movie;

您可以尝试一下,如果它不起作用,请将您的表移动到 public 架构中,或者 nudge the author of the schemaName support寻求帮助。

关于postgresql - Sailsjs 模型对象不为 Postgresql 返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22795298/

相关文章:

javascript - 查询嵌套对象键

ruby-on-rails - Heroku 迁移失败 UndefinedTable 错误

postgresql - URL 文本字段的查询优化

postgresql - 为什么这个 Postgres 查询抛出 "duplicate key value violates unique constraint"?

javascript - 我可以同步运行 Sails.js 服务吗?

javascript - Sails.js:我可以将一些服务/模型打包为 npm 并在 Sails.js 应用程序中加载 npm 吗?

javascript - 在 Sails 的 Waterline beforeUpdate Hook 中获取当前值

arrays - 将 PostgreSQL 数组数据类型解析为数组到 perl

html - 无法将 View 添加为 html 页面 (sails.js)

node.js - 在 nodeMailer 中设置附件路径的正确方法是什么?