Question

We have a few different entities. To explain a little better, here is example structure:

We have a lot of students. We have a lot of homeworks. Each homework has N (varies per homework) tasks. There is a junction table connecting students and tasks.

We want to assign some tasks to certain students in a homework. Let's say one homework has 5 possible tasks, we want each student to get one or more tasks.

At the moment, interface lists all students with some properties (for this case let's say - average grade, hair colour, name, gender etc.) and has 5 checkboxes (there are 5 tasks in selected homework). We can use filters to show only students with average grade of 4, or just female students etc.

After a while, you would assign 98% of students, but you notice there are 2% students without any tasks for selected homework (some statistics shows you that). Instead of going through all few thousand students, we'd like to create filter which would use existing filters AND apply additional filter which would show all students which have 0 tasks where task.homeworkId = X

Right now, in my head there is a possible solution, but I'm not sure if this is possible using breeze:

from students 
    where (OLD_FILTERS)
       and ((from junction_table 
           where task.homeworkId = selectedHomeworkId
                 and student.id = $parent_query.id).count() = 0)

I've been over this for a while now, can't come up with a nice clean solution. Only thing comming to my mind is pretty complex solution with manual filtering of all student properties and this new condition on server.

Thanks in advance for any help.

EDIT

Tables are related as follows:

student - junction table = 1 to many

task - junction table = 1 to many (basically, it's many-to-many student-task through junction entity)

task - homework = many to 1 (many tasks per one homework)

some perception on the model:

Student:
   Id
   Property1
   Property2
   ...

Homework
   Id
   Property1...

Task
   Id
   HomeworkId   // this is foreign key
   Property....


JunctionTable
   Id
   TaskId   // foreign key
   StudentId   // foreign key
Was it helpful?

Solution

Thanks to DenisK for help. We used older version of Breeze without the needed option. Solution is simple predicate:

var pred = breeze.Predicate.create("studentTasks", "any", "task.homeworkId", "==", homeworkId).not();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top