我的 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/