sequelize.js

Sequelize belongsToMany validation error

走远了吗. 提交于 2019-12-24 07:38:18
问题 I'm facing a problem since 3 days. I would like to create a multiple relation n:m in Sequelize but I'm getting an error message : " Unhandled rejection SequelizeUniqueConstraintError: Validation error ". So I have 3 tables : Serie. Episode. Season (in this table I would like to add relation to Serie and Episode ). Here is the definition of Serie : var Serie = sequelize.define('Serie', { idSerie: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, name: DataTypes.STRING }, {

Adding two of the same foreighn keys to a single model as two different fields in sequelize

给你一囗甜甜゛ 提交于 2019-12-24 07:36:01
问题 I am building the database structure for a project using sequelize. I am created the friends table for the project. Is it possible to set a user foreign key to two different fields (friender, friended) in the friend database table using sequelize. I know that I can create a foreign key using Friend.hasOne(User) User.hasMany(Friend) but that just assigns one field as a foreign key. I want to have two foreign keys that are the same model as two different fields. This is what I have so far for

Change model's table name runtime

那年仲夏 提交于 2019-12-24 06:35:06
问题 I am using Sequelize.js and need to save historical data till specific year and want to separate my tables by year's prefix for example prices_2010, prices_2011 e.g. I can create so tableName:"company_historical_" + new Date().getFullYear(); for current years table and it will use this name for table, but what if I want to store or query data of 2015 year and want to use models instead of raw queries. So how can I change table of use runtime. something like changeTable() method sequelize. 回答1

Sequelize Join Models Include many to many

别来无恙 提交于 2019-12-24 05:46:48
问题 Say I have three models like this var User = _define('user', { username: Sequelize.INTEGER }); var UserPubCrawl = _define('userpubcrawl', { user_id: Sequelize.STRING(64), // the user bar_id: Sequelize.INTEGER // 1 to many }); var Bars = _define('bar', { name: type: Sequelize.STRING, } The relationships are one meal User(one) --> UserPubCrawl (to many) --> Bars(to many) So 1 user can have multiple pubcrawls to many bars for a particular pub crawl I want to find all the bars that "Simpson" went

sequelize select and include another table alias

故事扮演 提交于 2019-12-24 04:02:13
问题 I'm using sequelize to acess a postgres database and I want to query for a city and for example include the "Building" table but I want to rename the output to "buildings" and return the http response but I have this error: { SequelizeEagerLoadingError: building is associated to city using an alias. You'v e included an alias (buildings), but it does not match the alias defined in your a ssociation. City.findById(req.params.id,{ include: [ { model: Building, as: "buildings" } ] }).then(city =>

Openshift node app failed to start

偶尔善良 提交于 2019-12-24 03:55:14
问题 I am failing to start my node-based application on Openshift. The application starts OK locally but node's automatic deployment (on push to the remote master repo) hits a cyclic problem with the log; DEBUG: Running node-supervisor with DEBUG: program './app/server.js' DEBUG: --watch '/var/lib/openshift/53dab282e0b8cdd367000131/app-root/data/.nodewatch' DEBUG: --ignore 'undefined' DEBUG: --extensions 'node|js|coffee' DEBUG: --exec 'node' DEBUG: Starting child process with 'node ./app/server.js

Query with date range using Sequelize request with Postgres in Node

我怕爱的太早我们不能终老 提交于 2019-12-24 03:26:03
问题 What I'm trying to do is to get rows in between two dates by using Sequelize ORM in Node.js. I'm using PostgreSQL. The problem is that the request that I'm making is interpreted incorrectly by Sequelize. Here is the code that I'm using to make request const dbresp = await Table.findAll({ attributes: [...], where: { ... createdAt: { $between: [new Date(Date(startDate)), new Date(Date(endDate))], // same effect // $lte: new Date(startDate), // $gte: new Date(endDate), }, }, logging: console.log

How to run sequelize db:migrate on Elastic Beanstalk EB with env vars? How to access .env vars in container commands?

…衆ロ難τιáo~ 提交于 2019-12-24 00:39:07
问题 How can I run sequelize db:migrate on ElasticBeanstalk with env vars? Running sequelize migrate fails since it cannot find the .env file. { Error: ENOENT: no such file or directory, open '.env' my master.config looks like: container_commands: 00_node_binary: command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node" 00_npm_binary: command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm" 01_migrations: command: npm

Limit and offset in association with include in sequelize

 ̄綄美尐妖づ 提交于 2019-12-24 00:22:47
问题 I have 2 models Country, City. They are associated with each other. City Belongs to Country. Now what I want to do is get cities list within a country query along with limit and offset for pagination if possible. If i do below it will list all cities within a country. What I need to do is be able to limit cities with limit and offset params. Country.findById(1, { include: [ { model: City, as: 'cities' } ] }); Country Model module.exports = (sequelize, DataTypes) => { let Country = sequelize

Change database connection depending on route in express.js with sequelize

别说谁变了你拦得住时间么 提交于 2019-12-23 15:55:22
问题 Is it possible to change the database connection in sequelize depending on the route? For example, Users have access to 2 different installations in a website: - example.com/foo - example.com/bar Upon login users are redirected to example.com/foo To get all their tasks for the foo site, they need to visit example.com/foo/tasks The bar site uses a separate database and thus if they want to get all their tasks for bar they have to go to example.com/bar/tasks Every installation has its own