Ember-data filter by has-many


#1

Given the following 2 models:

export default DS.Model.extend({
    slug: DS.attr('string'),
    name: DS.attr('string'),
    username: DS.attr('string'),
    auth: DS.belongsTo('auth', { async: true, inverse: 'user' }),
    avatarImage: DS.belongsTo('image', { async: true }),
    listingEvents: DS.hasMany('listingEvent', { async:true, inverse: 'users' }),
    email: DS.attr('string')
});

and

export default DS.Model.extend({
	currentUserAttending: DS.attr(),
  	name:DS.attr(),
  	slug: DS.attr('string'),
  	start:DS.attr('string'),
  	end:DS.attr('string'),
	eventInstanceSlug: DS.attr('string'),
  	location: DS.belongsTo('location', { async:true }),
  	artists: DS.hasMany('artist', { async:true }),
  	users: DS.hasMany('user', { async:true })
});

How can I fetch all listingEvents where users contains a user with id xxxxx

Is this possible?


#2

Depending on your api

you could do store.find(‘listingEvents’, {user: userId}) or you could do store.find(‘user’, userId).get('listingEvents)

Is that what you were asking?