Closed cesar2064 closed 8 years ago
You don't need an empty controller, where is your model ? Be sure to add it under your api/models/index.js
or it will be not load.
Also you can use the interactive shell to see if it's load. Just write app.models
to see loaded models
yes, all models were loaded and the orm works, I tried to save an user and it worked via shell. User.js
'use strict'
const Model = require('trails-model')
/**
* @module User
* @description handle user crud
*/
module.exports = class User extends Model {
static config (app,Sequelize) {
return {
options: {
classMethods: {
//If you need associations, put them here
associate: (models) => {
//More information about associations here : http://docs.sequelizejs.com/en/latest/docs/associations/
models.User.belongsToMany(models.Role, {
as: 'roles',
onDelete: 'CASCADE',
through:{
model: models.UserRole,
unique:false
},
foreignKey: "user_id"
})
}
}
}
}
}
static schema (app,Sequelize) {
return {
name: { type: Sequelize.STRING, allowNull: false },
password: Sequelize.STRING,
displayName: Sequelize.STRING
}
}
}
modesl/index.js
'use strict'
exports.User = require('./User')
exports.Role = require('./Role')
exports.UserRole = require('./UserRole')
/api/v1/user/find
will never work (not implemented on footprints) but GET /api/v1/user
should work... can you try GET /user
GET /user, doesn't work. My current dependencies :
"dependencies": {
"eslint": "^2.11.1",
"express": "^5.0.0-alpha.2",
"pg": "^4.5.6",
"trailpack-core": "^1.0.0",
"trailpack-express": "^1.0.1",
"trailpack-footprints": "^1.0.0",
"trailpack-repl": "^1.0.7",
"trailpack-router": "^1.0.2",
"trailpack-sequelize": "^1.0.0",
"trails": "^1.0.4",
"trails-controller": "^1.0.0-beta-2",
"trails-model": "^1.0.0-beta-2",
"trails-policy": "^1.0.2",
"trails-service": "^1.0.0-beta-2",
"winston": "^2.2.0"
}
What version of trailpack-sequelize
? Because here it's trailpack-mongoose
lol I'll try to generate a project with same dependencies to see if I can replicate
yes, sorry I edited my dependencies again, wrong dependencies :P
"trailpack-sequelize": "^1.0.0"
Do you need my other models?
Yes like this I can make full test like you. What's your node and npm version also please ?
node version: 6.2.0 npm version : 3.5.3
Role.js
module.exports = class Role extends Model {
static config () {
return {
options: {
classMethods: {
//If you need associations, put them here
associate: (models) => {
//More information about associations here : http://docs.sequelizejs.com/en/latest/docs/associations/
models.Role.belongsToMany(models.User, {
as: 'users',
onDelete: 'CASCADE',
through:{
model: models.UserRole,
unique:false
},
foreignKey: "role_id"
})
}
}
}
}
}
static schema (app,Sequelize) {
return {
name: { type: Sequelize.STRING, allowNull: false }
}
}
}
UserRole.js
module.exports = class UserRole extends Model {
static config () {
}
static schema (app,Sequelize) {
return {
role_id: {
type: Sequelize.INTEGER,
references: {
model: 'role',
key: 'id'
},
allowNull: false
},
user_id:{
type: Sequelize.INTEGER,
references:{
model: 'user',
key: 'id'
},
allowNull: false
}
}
}
}
Ho just see you're using footprints v1.0.0 witch is not the latest version
try "trailpack-footprints": "^1.0.0-beta-7",
Just try with this version and all is working for me :) Don't know why there a v1.0.0 on npm... Let me know if it's fix the problem
yes, so weird, when I use npm update --save, updates trailpack-footprints to v 1.0.0. In the other hand, With the "trailpack-footprints": "^1.0.0-beta-7" works now, thanks :D
Ok cool ! :) closing this then ^^
I release a v1.0.1 like this npm update
will be ok normally
I have created an user api and have the proper config. in the models, and because the orm is working now. But when I try to acces /api/v1/user or /api/v1/user/find, the server responds:
{"error":"Not found"}
UserController.js:
config/main.js:
config/footprint.js:
Are something wrong or missing in my configuration?