TypeError: Cannot read property 'belongsTo' of undefined

Issue I’m trying to Associations many to many, between 2 models "Trainer & Course" so I do third models "CourseTrainer" to try relation 1 to many. but I’m getting this error: C:\Users\DELL\Downloads\graphql-12.18.2020\graphql-12.18.2020\graphql-12.18.2020\serverapp\database\database.js:54 db.trainer.belongsTo(db.tblCourseTrainer, { ^ TypeError: Cannot read property ‘belongsTo’

Continue reading

Converting Miles to Degrees for postgis Sequelize

Issue Hi i am quering the PostGres database using POSTGIS extension as i want to get users in a radius i am following this post, where the following code is working fine Alert.findAll({ where: Sequelize.where( Sequelize.fn(‘ST_DWithin’, Sequelize.col(‘position’), Sequelize.fn(‘ST_SetSRID’, Sequelize.fn(‘ST_MakePoint’, req.query.long,

Continue reading

How to do a query in Sequelize?

Issue I’ve an existing Postgres database. Throught sequelize-auto, I generated the models for the existing database. For example, let’s look at the tc_devices table (tc_devices.js): const Sequelize = require(‘sequelize’); module.exports = function(sequelize, DataTypes) { return sequelize.define(‘tc_devices’, { id: { autoIncrement:

Continue reading

Sequelize OR condition object

Issue By creating object like this var condition= { where: { LastName:”Doe”, FirstName:[“John”,”Jane”], Age:{ gt:18 } } } and pass it in Student.findAll(condition) .success(function(students){ }) It could beautifully generate SQL like this “SELECT * FROM Student WHERE LastName=’Doe’ AND FirstName

Continue reading

Select from multiple tables Sequelize

Issue I’m currently developing a system using sequelize and I need a to do a query getting data from multiple tables like this: Select Courses.id, Rooms.DisplayLabel, Periods.DisplayName, Subjects.Name from Rooms, Periods,Subjects, Courses where Periods.id = Courses.PeriodId and Rooms.id=Courses.RoomId and Subjects.id

Continue reading

How can I bind a variable to sequelize literal?

Issue I have this subquery that is used to check the existence of a column related to the source model. const defaultingLoans = await Loan.findAll({ where: { [Op.and]: database.sequelize.literal(‘EXISTS(SELECT * FROM “Instalments” WHERE “Instalments”.”loanId” = “Loan”.”id” AND “Instalments”.”status” = ‘pending’)’)

Continue reading

Sequelize One to Many Association Update won't work

Issue This is how my two models are connected: DebitInvoice.hasMany(DebitInvoiceProduct, { onDelete: ‘CASCADE’, onUpdate: ‘CASCADE’, foreignKey: ‘invoice_serial’ }); DebitInvoiceProduct.belongsTo(DebitInvoice,{ foreignKey: ‘serial’ }); I am trying to update DebitInvoice and while doing so I also need to delete previous DebitInvoiceProduct rows

Continue reading

Sequelize One to Many Association Update won't work

Issue This is how my two models are connected: DebitInvoice.hasMany(DebitInvoiceProduct, { onDelete: ‘CASCADE’, onUpdate: ‘CASCADE’, foreignKey: ‘invoice_serial’ }); DebitInvoiceProduct.belongsTo(DebitInvoice,{ foreignKey: ‘serial’ }); I am trying to update DebitInvoice and while doing so I also need to delete previous DebitInvoiceProduct rows

Continue reading

Having an issue writing a functional sequelize query for case-when

Issue I am trying to put this query for case when, but it’s not working: [db.Sequelize.literal(‘case when "survey_session_question->scq"."eng_question_text" is not null then "survey_session_question->scq"."eng_question_text" else "survey_session_question->scq->base_question"."eng_question_text" end’), ‘eng_question_text’] I should be getting the values where the field eng_question_text is not null,

Continue reading

Sequelize column Table.createdAt does not exist

Issue I have these two tables: const AdminUser = sequelize.define(‘AdminUser’, { adminUserId: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, unique: true, allowNull: false, primaryKey: true }, adminUsername: { type: ‘citext’, unique: true, allowNull: false }, password: { type: DataTypes.STRING, allowNull: false },

Continue reading

Sequelize multiple HasMany issue

Issue My schema db.user.hasMany(db.appointment, { foreignKey: ‘user_id’ }) db.user.hasMany(db.appointment, { foreignKey: ‘doctor_id’ }) db.appointment.belongsTo(db.user, { foreignKey: ‘user_id’ }) db.appointment.belongsTo(db.user, { foreignKey: ‘doctor_id’ }) The table user is common for doctor and user After that I create 2 appointments await Appointment.create({user_id:

Continue reading