Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 书架JS未定义到TableName_Javascript_Mysql_Node.js - Fatal编程技术网

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版本中修复