My data model is described below. I would like to write a queries that would return:
- list of reviews in a given department
- list of specific types of training
- list of reviews in a given college
So starting from the department, here is what I tried to do:
Query for reviews in the department:
var department = this.store.findRecord('department',params.department_id)
var reviews = this.store.query('review' {'faculty.department':department});
Query for specific trainings:
var design = this.store.query('training',{'faculty.department':department, filter:{type:'ATC Design Course (DQOC)'}});
Query for the reviews of all the faculty working in a given college:
var college = this.get('college');
var cid = college.getProperties("id").id
var reviewQuery = store.query('review',{'faculty.department.college._id':college._id});
var trainingQuery = store.query('training',{'faculty.department.college._id':college._id});
Neither of the queries give me results I am looking for. It seems they all evaluate to query that finds all results of given model type, for example query below returns all training models of all types.
var design = this.store.query('training',{'faculty.department':department, filter:{type:'ATC Design Course (DQOC)'}});
I need a help with rewriting the queries so they will return correct results. What is the best practice in this case, and how should I implement it?
Is it possible to query model bottom app starting from reviews->faculty->department->college?
Alternatively I could go with top down approach, and query all departments, instructors and so on with some nested for loop structure but would like to go other way if possible. How would this query look like?
I will appreciate any help.
Colleges:
export default DS.Model.extend({
name: DS.attr('string'),
departments: DS.hasMany('department')
});
Departments
export default DS.Model.extend({
name: DS.attr('string'),
faculty:DS.hasMany('faculty'),
college: DS.belongsTo('college')
});
Faculty:
export default DS.Model.extend({
profile_image:DS.attr('string'),
firstname: DS.attr('string'),
lastname: DS.attr('string'),
salutation: DS.attr('string'),
email: DS.attr('string'),
department: DS.belongsTo('department'),
reviews: DS.hasMany('review'),
training: DS.hasMany('training')
});
Reviews
export default DS.Model.extend({
faculty: DS.belongsTo('faculty'),
courseName:DS.attr('string'),
internalDate:DS.attr("date"),
externalDate:DS.attr("date"),
funDate:DS.attr("date"),
recertificationDate:DS.attr("date")
});
Training
export default DS.Model.extend({
type: DS.attr('string'),
faculty: DS.belongsTo('faculty'),
date:DS.attr("date")
});
FIRST EDITS Question How can I get all reviews in a given college? var rquery = store.query('review', {faculty.department.college._id : college._id})
or
var rquery = store.query('review', {faculty.department.college : college})
gives me a syntax error.
SyntaxError: quality-online/components/quality-chart.js: Unexpected token (50:44)