我尝试遵循示例 here ,但是运气不佳。
我在 user.js 文件中有用户模型:
import thinky from './thinky';
let type = thinky.type;
let User = thinky.createModel('User', {
id: type.string(),
username: type.string(),
});
export default User;
let Game = require('./game');
User.hasAndBelongsToMany(Game, "games", "id", "id");
game.js 文件中的游戏模型:
import thinky from './thinky';
let type = thinky.type;
let Game = thinky.createModel('Game', {
id: type.string(),
host: type.string()
});
export default Game;
let User = require('./user');
Game.hasAndBelongsToMany(User, "players", "id", "id");
当我尝试将它们导入 test.js 文件(在其中创建用户和游戏的实例)时,我得到hasAndBelongsToMany 的第一个参数必须是模型
我尝试不用es6语法来编写它,仍然不起作用......
最佳答案
我的示例是,如果您将导出默认值更改为 module.exports,一切都应该正常
关于javascript - 单独文件中的 thinky 模型 : how to handle cyclical/circular dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535343/