Ember - 按相关模型中的属性查询模型

时间:2015-03-24 20:41:33

标签: ember.js ember-data

我正在尝试查询具有特定标记的已发布帖子的帖子模型。我的模型看起来像这样:

var Post = DS.Model.extend({
    tags: DS.hasMany('tag', { async: true }),
    title: DS.attr('string'),
    published: DS.attr('boolean'),
});

var Tag = DS.Model.extend({
    posts: DS.hasMany('post', { async: true }),
    name: DS.attr('string')
});

我已经能够使用find()方法在我的查询中发布帖子:

this.get('store').find('post', {published: true});

但我不明白如何查询属于相关模型的属性。我很感激任何指导,谢谢!


修改

我使用filter()提出了这个解决方案,似乎效果很好。

var self = this;
var store = this.get('store');

store.find('post', {published: true}).then(function() {
    self.set('content', store.filter('post', function(post) {
        return post.get('tag.name') === 'Photography';
    }));
});

0 个答案:

没有答案
相关问题