Not filterBy properly;

First of all, every class has many subjects and every class has many students. Every subject and student belongs to one class. Also, every subject and student has many grades. But one grade belongs to one subject and one student.

So, before I insert mark (property of the model grade) for a student from a certain subject. It correctly insert a mark for it, but there are two bugs:

  1. It always creates a new object of a grade for the first time when I enter that option, even though it is an existing subject and student with their id’s and also at the same time writes an error “Error: no record was found at …”

  2. Once I insert a mark from that subject and try to insert a mark from another subject it always keep inserting marks from the first subject (previous one);

-I will leave here my snippets of a code from models, template, controller and sample of data from firebase:


import DS from 'ember-data';

export default DS.Model.extend({
	name: DS.attr('string'),
	subjects: DS.hasMany('subject'),
	students: DS.hasMany('student')


import DS from 'ember-data';

export default DS.Model.extend({
	marks: DS.attr('array'),
	subject: DS.belongsTo('subject'),
	student: DS.belongsTo('student')


import DS from 'ember-data';

export default DS.Model.extend({
	title: DS.attr('string'),
	class: DS.belongsTo('class'),
	students: DS.hasMany('student'),
	grades: DS.hasMany('grades')


import DS from 'ember-data';

export default DS.Model.extend({
	firstName: DS.attr('string'),
	lastName: DS.attr('string'),
	class: DS.belongsTo('class'),
	grades: DS.hasMany('grade')


import Ember from 'ember';

export default Ember.Controller.extend({
  showS: false,
  mark: "",

  insertMark(val, val2){
		var student = this.get('store').peekRecord('student', val);
		var subject = this.get('store').peekRecord('subject', val2);
		var mark  = this.get('mark');

		var grades = this.get('store').peekAll('grade');
		grades.filterBy('student', student).filterBy('subject', subject);

		if(grades.get('firstObject') == null){
			this.get('store').createRecord('grade', {
				marks: [mark],
				student: student,
				subject: subject


<br> <br> <br> <br> <br>


<h2> Chosen class: {{}} </h2>


<i> Current students in class: </i> <br>

{{#each model.students as |student|}}
  <li> {{student.firstName}}  {{student.lastName}} </li>
  <button class="choose" {{action 'showSubjects'}}> Show subjects </button>
  {{#if showS}}
    <br> Current subjects in class: 
    {{#each model.subjects as |subject|}}
      <br> <b> {{subject.title}} </b>
       Choose grade: 
      <select onchange={{action (mut mark) value="target.value"}}>
        <option value="1"> 1 </option>
        <option value="2"> 2 </option>
        <option value="3"> 3 </option>
        <option value="4"> 4 </option>
        <option value="5"> 5 </option>
      <button {{action 'insertMark'}}> Insert mark for student </button>
  <b> Currently there are no students for the class! </b>


-Sample of data from firebase: