gpt4 book ai didi

javascript - 书架 JS undefined throughTableName

转载 作者:行者123 更新时间:2023-11-30 23:05:28 33 4
gpt4 key购买 nike

我正在尝试通过 attachments 表从 files 表中获取 filenames 以获取帖子。

附件表:

post_id, file_id

文件表:

id, filename

帖子表

attachments = 1,2,3

post 表中的attachments 列包含一个attachment_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');

最佳答案

这是一个错误,已在 0.6.6 版本中修复。

关于javascript - 书架 JS undefined throughTableName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116804/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com