firebaseember.jsemberfire

Why does my Ember store.query() query everything?


In Ember.js,

I am trying to perform a query of all posts with a matching key. Btw, this is in Firebase. My data looks something like this:

post example

I'm trying to query specific posts based off the key property (multiple posts may have the same key property value).

So here is my model(params) in my route

route/stuff.js

export default Ember.Route.extend({
    model(params) {
        console.log(params.site_id);
        return this.store.query('post', { "key": params.site_id} );
    }
})

And here is me trying to display my posts in my template:

template/stuff.hbs

{{#each model as |post|}}
<div class="panel panel-default">
    <div class="panel-heading">
        Post Title: {{post.title}}
    </div>
    <div class="panel-body">
        <div class="col-lg-6 col-md-6 col-sm-6 margin-top-1em">
            <ul class="li-type-none">
                <li>Post Author: {{post.author}}</li>
            </ul>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-6">
            <ul class="nav nav-pills margin-top-small">
                {{#link-to 'posts.edit' post.id class='btn btn-success btn-s'}}Edit{{/link-to}}
                <button class="btn btn-danger btn-s" {{action 'deletePost' post}}>Remove Post</button>
            </ul>
        </div>
    </div>
</div>
{{/each}}


{{outlet}}

And, the good news is that my posts will display. The bad news is that ALL posts display. Even ones that don't have the right key. Why is my query returning all the posts instead of only the ones that have the right key attribute?

Here is some extra information that maybe helpful:

model/post.js

import DS from 'ember-data';

export default DS.Model.extend({
  author: DS.attr('string'),
  title: DS.attr('string'),
  content: DS.attr('string'),
  key: DS.attr('string'),
  date: DS.attr('date', { defaultValue() { return new Date(); }}),
  site: DS.belongsTo('site'),
  isLocked: DS.attr('boolean'),
  lockedContent: DS.attr('string'),
  metaData: DS.attr('string')
});

Also, here is how it looks in the URL (note that the key attribute is passed into the url)

http://localhost:4200/posts/-D2312jsj23u1828u42/stuff

Thank you!


Solution

  • Your query rules vary depending on your adapter.

    That means that this solution will only work if you are using the emberfire adapter. If you are not using the emberfire adapter, you need to look at your adapter's documentation to see how querying works for your specific adapter

    export default Ember.Route.extend({
        model(params) {
            console.log(params.site_id);
            return this.store.query('post', {orderBy: 'author', equalTo: "Cameron Fife"} ).then(function(res) {
                return res
            });
        }
    });