Queries for related items by ID - Ottoman

n1ql

#1

Is it possible to define an n1ql query on an ottoman model to be executed as an easy method, to look up related documents?

I’m looking for something like what is in the ottoman docs under “queries” for looking something up by type, like this:

ottoman.model('Post', {
  user: {ref:'User'},
  title: 'string',
  body: 'string'
});

ottoman.model('User', {
  name: 'string'
}, {
  queries: {
    myPosts: {
      of: 'Post',
      by: 'user'
    }
  }
});

Except the difference is that I’d like to look up another model by a property and value. Say I have two ottoman models “Post” and “User”, and I’m taking their data from elsewhere. Both have an amId field; in User, I have another field called postId. I’d really like to write a simple method that will fetch all Post objects where myUser.postId = post.amId;

This would be very useful to have; so many data sets come from relational DBs with primary/foreign key joins like this, it would help connect many existing data sets.