Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db.rel.find(type, id) returns all 'type' docs, not only doc with that id. #44

Closed
ramonsan opened this issue Oct 1, 2015 · 1 comment

Comments

@ramonsan
Copy link

ramonsan commented Oct 1, 2015

Also happens with db.rel.find(type, ids). If you take the example from readme:

          var db = new PouchDB('mydb');
          db.setSchema([
              {singular: 'author', plural: 'authors', relations: { books: {hasMany: 'book'}}},
              {singular: 'book', plural: 'books', relations: {author: {belongsTo: 'author'}}}
          ]);
          db.rel.save('author', {
              name: 'George R. R. Martin', id: 1, books: [6, 7]
          }).then(function () {
              return db.rel.save('book', { title: 'A Game of Thrones', id: 6, author: 1});
          }).then(function () {
              return db.rel.save('book', {title: 'The Hedge Knight', id: 7, author: 1});
          }).catch(console.log.bind(console));

And then you want find book with id 7:

          db.rel.find('book',7).then(function(doc){
              console.log(doc);
          });

You got as result all books:

{
    "books" : [
        {
            "title" : "A Game of Thrones",
            "author" : 1,
            "id" : 6,
            "rev" : "1-16ce4f20eae39bd0655f00f81973dd14"
        },
        {
            "title" : "The Hedge Knight",
            "author" : 1,
            "id" : 7,
            "rev" : "1-7d35db00e3b7df172e33173eded5ab72"
        }
    ],
    "authors" : [
        {
            "name" : "George R. R. Martin",
            "books" : [
                 6,
                 7
            ],
            "id" : 1,
            "rev" : "1-c4c9b023321d67787d737421837988e3"
        }
    ]
}
@nolanlawson
Copy link
Member

Thanks for reporting! This is actually by design; you can omit dependent objects by using async relations: https://github.com/nolanlawson/relational-pouch#async-relationships

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants