Closed grahamb closed 9 years ago
I doubt this can be written directly in sequelize, but to find periods without overlap, you could do something like:
SELECT * FROM programPeriod p1 WHERE NOT EXIST(
SELECT * FROM programPeriod p2 WHERE p1 overlaps with p2
)
JOIN on schedule
JOIN on program
Should have mentioned: this is Postgres. I'm getting a syntax error with the above query:
# SELECT * FROM "ProgramPeriods" p1 WHERE NOT EXIST(SELECT * FROM "ProgramPeriods" p2 WHERE p1 overlaps with p2) JOIN on "Schedule" JOIN on "Programs";
ERROR: syntax error at or near "SELECT"
LINE 1: SELECT * FROM "ProgramPeriods" p1 WHERE NOT EXIST(SELECT * F...
Well, something similar then - I'm not completely versed in PG syntax :)
Closing this issue, since it is neither a bug report nor a feature request.
For general sequelize questions, please use StackOverflow or Google groups. - I know you already posted on google groups, but the issues queue should be limited to bugs and feature request
I posted this on the Google Group five days ago and didn't get any takers, so I figured I'd try here:
I'm working on an app that handles program scheduling for a large scout camp. The primary models I'm concerned with are:
With this setup, I'm able to query for all the
Unit
s assigned to aProgram
'sProgramPeriod
:Program.find({ where: { id: 1 }, include: [ { model: models.ProgramPeriod, include: [ models.ProgramPeriod.associations.Schedule ] } ] } )
…and I can query for a
Unit
's schedule ofProgram
s:Unit.find({ where: { id: 174 }, include: [ { model: models.ProgramPeriod, include: [models.ProgramPeriod.associations.Program] } ] })
I'm having trouble with figuring out a few things needed for scheduling. Assume that unit id 174 has 10 participants. I need to, for any given
Program
, query for allProgramPeriods
that have enough space available, and don't conflict with any otherProgramPeriod
time already on the Unit's schedule.I'm not tied to any of the above associations; I can change things around if it makes accomplishing this easier.
Thanks!