mardi 17 janvier 2017

Newbie Emberfire Querying

I am having trouble with simple EmberFire queries. I want to find a department object by name, and then add it to a college departments according to the data model described below.

The error I am receiving is:

TypeError: Cannot read property 'pushObject' of undefined

What am I doing wrong?

              store.query('college', {orderBy: 'name', equalTo: "CAS"}).then(function(c){
              var college = c
              console.log(college);
              dept.set('college',college);
              college.get('departments').pushObject(dept);
              dept.save();
              college.save()

            }
          )

Where department is:

  store.query('department', {orderBy: 'name', equalTo: "Testing One"}).then(function(depts){
              // var dept = depts.get('content')[0]
              var dept = depts})

Here is my full query:

    findOne(){
      var store = this.store
      // store.query('department', {orderBy: 'name', equalTo: "Testing One"}).then(function(depts){
      store.query('department', {orderBy: 'name', equalTo: "Testing One"}).then(function(depts){
          // var dept = depts.get('content')[0]
          var dept = depts
          console.log(dept);
          //Add it to college
          store.query('college', {orderBy: 'name', equalTo: "CAS"}).then(function(c){
              var college = c//.get('content')[0]
              console.log(college);
              dept.set('college',college);
              college.get('departments').pushObject(dept);
              dept.save();
              college.save()

            }
          )
      })
},

Department:

export default DS.Model.extend({
   name: DS.attr('string'),
   faculty:DS.hasMany('faculty'),
   college: DS.belongsTo('college')
});

College:

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  departments: DS.hasMany('department')
});

EDIT: c object from query:

Class
__ember1484688357664
:
"ember632"
__ember_meta__
:
Meta
__firebaseCleanup
:
()
_super
:
ROOT()
_updatingPromise
:
null
content
:
(...)
get content
:
GETTER_FUNCTION()
set content
:
SETTER_FUNCTION(value)
isLoaded
:
true
isUpdating
:
false
links
:
EmptyObject
manager
:
Class
meta
:
EmptyObject
query
:
Object
store
:
Class
type
:
quality-online@model:college:
__proto__
:
Class




Aucun commentaire:

Enregistrer un commentaire