1

I'm new to Ember, and have been impressed so far by how succinct everything is. Though querying data with EmberFire seems a little odd. For instance, in a component's js I can find a record with :

store.query('user', { orderBy: 'email', equalTo: email }).then((response) => {
  // expect response to be an object, or an array of objects
  // but its actually a class, and needs the following to return data      
  var user = response.get('content')[0]._data;

  // now able to access properties as originally expected
  console.log(user.email);
});

While the above works, it doesn't feel very elegant. Am I missing something? As far as I can see the documentation stops at explaining the query, so any help as to the proper way of accessing a model's properties would be much appreciated.

Thanks

xcskier56
  • 611
  • 3
  • 11
Sj.
  • 1,402
  • 1
  • 12
  • 9

2 Answers2

0

store.query returns a promise that resolves to a AdapterPopulatedRecordArray. So yes, it should be returning a class.

If you're expecting only 1 record to be returned, then you should use queryRecord.

store.queryRecord('user', { orderBy: 'email', equalTo: email }).then((user) => {
  // now able to access properties as expected
  console.log(user.get('email'));
});

If you're expecting more than 1 record, keep using query and you'll be able to loop through the user results that are returned.

xcskier56
  • 611
  • 3
  • 11
  • "You tried to make a query but your adapter does not implement `queryRecord`", name: "Error"…}description: undefinedfileName: undefinedlineNumber: undefinedmessage: "Assertion Failed: You tried to make a query but your adapter does not implement `queryRecord`"name: – Janusz Chudzynski Jan 17 '17 at 17:39
  • What version of ember and adapter are you using? – xcskier56 Jan 17 '17 at 17:42
  • "emberfire": "2.0.4" ember-cli: 2.8.0 node: 4.0.0 – Janusz Chudzynski Jan 17 '17 at 17:43
  • Well, unfortunately, it looks like the ember fire adapter does not adhere to the ember data api, and so it does not implement `queryRecord`. https://github.com/firebase/emberfire/issues/405 – xcskier56 Jan 21 '17 at 00:01
0

This problem has existed for a while and it's because EmberFire was deprecated before anybody wrote an elegant way to query this way.

This add-on solves the problem, and will let you query pretty much any way you can imagine with the filterCustom method.

Tom
  • 350
  • 4
  • 21