Comments (6)
most probably it is due to the fact that sequelize changed interface in the latest version. i will update it during the weekend and let you know
from adminjs.
Hi - thanks for issue :).
Can you write what import sqModels
(from '../sq-models') are in your case and what is the schema of your model (sqModels.User from the example)
from adminjs.
sqModels index.js:
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/seq.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs.readdirSync(__dirname).filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
}).forEach(file => {
const model = sequelize.import (path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
And User model:
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
name: {
type: DataTypes.STRING,
validate: {
len: [0, 30]
}
},
username: {
type: DataTypes.STRING,
allowNull: {
args: false,
msg: 'Please enter your username'
},
unique: {
args: true,
msg: 'Sorry, this username is taken'
}
},
email: {
type: DataTypes.STRING,
unique: {
args: true,
msg: 'Sorry, this username is taken'
},
validate: {
isEmail: {
args: true,
msg: 'Please enter a valid email address'
}
}
},
password: {
type: DataTypes.STRING,
allowNull: {
args: false,
msg: 'Please enter a password'
},
validate: {
isNotShort: (value) => {
if (value.length < 8) {
throw new Error('Password should be at least 8 characters');
}
}
}
},
bio: {
type: DataTypes.STRING,
validate: {
len: [0, 150]
}
},
cuid: {
type: DataTypes.STRING,
allowNull: true
},
phoneNumber: {
type: DataTypes.STRING
},
isPrivate: {
type: DataTypes.BOOLEAN
},
isSuperUser: {
type: DataTypes.BOOLEAN,
allowNull: true
},
needToVerifyEmail: {
type: DataTypes.BOOLEAN
},
needToVerifyPhoneNumber: {
type: DataTypes.BOOLEAN
},
emailVerificationNumber: {
type: DataTypes.INTEGER
},
cellphoneVerificationNumber: {
type: DataTypes.INTEGER
},
followerCount: {
type: DataTypes.INTEGER,
defaultValue: 0
},
followingCount: {
type: DataTypes.INTEGER,
defaultValue: 0
},
qoins: {
type: DataTypes.INTEGER,
defaultValue: 0
},
image: {
type: DataTypes.STRING
}
}, {});
User.associate = models => {
User.hasMany(models.UserImage, {
as: 'imagesPath',
constraints: false,
allowNull: true
});
User.hasMany(models.Relation, {
as: 'selfRelations',
foreignKey: 'fromUser',
constraints: false,
defaultValue: null
});
User.hasMany(models.Relation, {
as: 'othersRelations',
foreignKey: 'toUser',
constraints: false,
defaultValue: null
});
};
User.findByUsername = async (username, passId) => {
let filter = {
where: {
username: username
},
attributes: [
'followerCount',
'followingCount',
'image',
'qoins',
'isPrivate',
'name',
'bio',
'id',
'username'
],
include: ['imagesPath']
}
if (passId)
filter.attributes.push('id')
let user = await User.findOne(filter);
return user
}
User.getFullUser = async username => {
let user = await User.findOne({
where: {
username: username
},
attributes: {
exclude: ['emailVerificationNumber', 'cellphoneVerificationNumber', 'createdAt', 'updatedAt', 'password']
},
include: ['imagesPath']
});
return user
}
return User;
};
from adminjs.
@wojtek-krysiak Awesome, I was getting the same thing with MySQLv5.7.23 and I was only grabbing the name from the users table, I couldn't figure out why I was getting that TypeError: Cannot convert undefined or null to object.
😅
from adminjs.
Gents - fixed that in admin-bro-sequelizejs v0.2.2 - please update your package.json files and let me know if it still occurs.
from adminjs.
It works, thanks.
from adminjs.
Related Issues (20)
- [Bug]: adminjs/cli `unable to resolve dependency tree` project init falied for nestjs with typeorm and postgres HOT 2
- [Bug]: Not able to build after adding admin-bro HOT 1
- [Feature]: how i can redirect to url from actions handler HOT 1
- [Bug]: Errors during transpile HOT 1
- Want to add new list option without url and want on click event on that HOT 1
- How to update mongoDB with custom component in list HOT 1
- [Feature]: Auto refresh table data based perdiocally HOT 1
- Can't see console.log HOT 1
- Leaflet Maps not properly rendering HOT 2
- process.env.ENV_VARIABLE is undefined HOT 2
- Map leaflet property position cannot be changed HOT 1
- Leaflet shows error when creating a new record HOT 3
- @adminjs/relations rendering error: Error: Component "RelationsShowPropertyComponent" has not been bundled HOT 1
- [Bug]: Admim js Dashboard takes very long time to load the page. HOT 1
- [Feature]: Overriding the create new resource actions button HOT 1
- [Feature]: [@adminjs/relations] Add custom properties/columns.
- [Feature]: function for guard instead of only string
- How can I query a record or a list of records with exact matching property values?
- [Bug]: Custom Component is taking too long to load and resulting in heap memory out of usage. HOT 2
- [Bug]: [@admins/relations] custom action icon not shown
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adminjs.