我尝试按照此处的示例进行操作,但是没有运气。
我在 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 文件时,我在其中创建用户和游戏的实例,我得到First argument of hasAndBelongsToMany must be a Model
我试图在没有 es6 语法的情况下编写它,仍然无法正常工作......