简体   繁体   中英

How can i translate query to sequelize?

select reservation_datetime
from LectureReservation
Inner Join Lecture
On LectureReservation.lecture_id = Lecture.id
Where Lecture.mentor_id = 1

This is my query and I want to change it to sequelize like

if (req.params.id) {
            LectureReservation
            .findAll({
                include: [{
                    model: Lecture,
                    where: { mentor_id: req.params.id },
                }],
                attributes: ['reservation_datetime'],
                where: {
                    lecture_id: Lecture.id,
                },

this.. I tried it so hard but can't find solution and my postman keep showing me

"name": "SequelizeEagerLoadingError"

this err..

plz help me to translate query to sequelize..!

Sequelize will do _outer join without required = true.

The errors you have received usually is from association problem.

Try set logging:console.log and check the raw query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM