-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property '[model name]' of undefined #351
Comments
This is because you are not properly handling the circular reference |
I've removed all relations and imports that may be circular, but the error still persists. |
Code? |
api.js import models from './models';
models.User.hasMany(models.ItemLocation, 'locations', 'id', 'userId');
models.ItemLocation.belongsTo(models.User, 'user', 'userId', 'id'); models.index user.js import { createModel, type, r } from '../utils/thinky.js';
let User = createModel('User', {
id: type.string(),
name: type.string().required().alphanum().min(5),
email: type.string().email().required(),
password: type.string().required(),
joinedOn: type.date().default(r.now())
});
export default User; itemlocation.js import { createModel, type, r } from '../utils/thinky.js';
let ItemLocation = createModel('ItemLocation', {
id: type.string(),
name: type.string().required().alphanum(),
createdAt: type.date().default(r.now())
});
export default ItemLocation; Quite perplexing. Thanks for your time Edit: I tried moving everything into one file and that still doesn't resolve the error. |
That's a typescript syntax right? What's the JS output? |
No, it's ES6 (through Babel). I discovered the problem, I think. The restructuring assignment in the import ( |
I got the same things through babel. |
It may be worth opening an issue on the babel tracker if it doesn't respect the order of import/export. |
@eranimo I'm running into the same error as mentioned in your first post. So you just changed your import to |
Actually, the OP's original problem wasn't due to Circular Dependency. It was caused by not binding the If you still want to get rid of export const createModel: typeof thinky.createModel = thinky.createModel.bind(thinky); |
I have the following structure:
utils/thinky.js
models/user.js
models/index.js
When I run
import models from './models';
I get the following error:The text was updated successfully, but these errors were encountered: