filterBy using a hasMany relationship


My chatroom model includes a hasMany comments and my user model also includes hasMany comments.

With my chatroom model I’m trying to find my comments for the chatroom. using:

var mySelf = this;
return this.chatroomModel.get('comments').then((myComments) => {
     var commentList = myComments.filterBy('user', mySelf.get('user').get('currentUser'));
     console.log("Array: ", commentList );

If I filter by any comment property it works but filtering by user does not. Any ideas as to why?

The user property on the comment model probably returns a promise (if you’re using async relationships like you should be). Since filterBy uses the triple equals for equality (===) and the promise objects are not the same exact JS objects, they are all getting filtered out.

If this is the case, check out the References API. See this blog post:

1 Like