Javascript 书架JS未定义到TableName
我正试图通过一篇文章的附件表从文件表中获取文件名 附件表:Javascript 书架JS未定义到TableName,javascript,mysql,node.js,Javascript,Mysql,Node.js,我正试图通过一篇文章的附件表从文件表中获取文件名 附件表: post_id, file_id 文件表: id, filename 邮局 attachments = 1,2,3 post表中的“附件”列包含附件id的列表。 我想获取这些1,2,3附件的每个文件名 所以我建立了一段关系 我的帖子模型: require('./file'); require('./attachment'); ... attachments: function() { return console.log(
post_id, file_id
文件表:
id, filename
邮局
attachments = 1,2,3
post表中的“附件”列包含附件id的列表。
我想获取这些1,2,3附件的每个文件名
所以我建立了一段关系
我的帖子模型:
require('./file');
require('./attachment');
...
attachments: function() {
return console.log(this.hasMany('File').through('Attachment'));
},
console.log显示:
{ type: 'hasMany',
target:
{ [Function]
extend: [Function],
include: [Function],
__super__: [Object],
forge: [Function],
collection: [Function] },
targetTableName: 'files',
targetIdAttribute: 'id',
foreignKey: undefined,
parentId: 1,
parentTableName: 'posts',
parentIdAttribute: 'id',
parentFk: 1,
throughTarget: 'Attachment',
throughTableName: undefined,
throughIdAttribute: undefined,
throughForeignKey: undefined,
otherKey: undefined },
第一个问题是,为什么不检测附件表名?我已经这样设置了:
var Attachment = Bookshelf.Model.extend({
tableName: 'attachments'
});
module.exports = Bookshelf.model('Attachment', Attachment);
最后,当我查询页面时,它只返回{}为什么?只是个初学者
我还在所有模型文件上使用注册表
Bookshelf.plugin('registry');
这是一个bug,在0.6.6版本中修复