我试着学习这里的例子,但是没有运气。
我在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语法的情况下编写它,但仍然不起作用.
发布于 2015-12-11 05:15:20
如果您将导出默认值更改为module.exports,则一切都应正常工作
发布于 2015-11-18 14:07:29
我们需要避免循环引用所以..。
user.js
import thinky from './thinky';
let type = thinky.type;
let User = thinky.createModel('User', {
id: type.string(),
username: type.string(),
});
export default User;game.js
import thinky from './thinky';
let type = thinky.type;
let Game = thinky.createModel('Game', {
id: type.string(),
host: type.string()
});
export default Game;index.js
import User from './user';
import Game from './game';
Game.hasAndBelongsToMany(User, "players", "id", "id");
User.hasAndBelongsToMany(Game, "games", "id", "id");
export {User, Game};发布于 2016-05-09 15:51:27
您还可以尝试此加载程序,其目的就是加载多个模型定义并将它们提供给您的应用程序。
https://stackoverflow.com/questions/32535343
复制相似问题