Start a new topic

Ember.js Library - searching relationships

What is the proper way to query for a relationship?

I.e. if you have a post that hasMany tags, and you wanted to search the post model for a specific tag name, how would you do that?

I know this doesn't work:

var query = new Kinvey.Query();

query.matches('', '^findme.*');'post', query);

Hey Leo, I just wanted to know we've seen your question, apologies for the delay due to the migration.
I am assuming both your post and tag have the adapter set to the `Kinvey.RESTAdapter`? In that case, tags will be stored separately from posts in the database. To query for posts with a specific tag, you can query `tag._id` to equal the tag id:


var query = new Kinvey.Query();

query.equal('tag._id', );'post', query);

So I need to first search for the tag name to get the ID and then search for the post's tag ID? Do you have plans to improve the ORM so that we are able to just search for the tag's name through the post object?
There are plans to add a feature to the Ember library to, in your case, embed tags inside posts (instead of converting them to references) when saving the data. This way, you could indeed just look for the name.

If you prefer to store the tags in a separate collection, then no, there are no plans to change this. [This blog post]( might come in handy to learn more on data modeling.
Login or Signup to post a comment