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

Heelp!!!! new post not adding to authors #101

Open
jcpc91 opened this issue Jun 4, 2018 · 2 comments
Open

Heelp!!!! new post not adding to authors #101

jcpc91 opened this issue Jun 4, 2018 · 2 comments

Comments

@jcpc91
Copy link

jcpc91 commented Jun 4, 2018

my scheme is the same like the example
[
{singular: 'author', plural: 'authors', relations: { books: {hasMany: 'book'}}},
{singular: 'book', plural: 'books', relations: {author: {belongsTo: 'author'}}}
]

at some point in the app i created an author
db.rel.save('authors', {id: '1', name: 'Administrador', email: 'admin@mail.com', username: 'admin', password: 'xxx'})
like in the real world does not have any Post
when the author add new post does not have the related id

db.rel.find('authors')

authors: [{
'authors': {
id: '1', name: 'Administrador',
email: 'admin@mail.com',
username: 'admin',
password: 'xxx',
posts: []
}]

but what expected to see

authors: [{
'authors': {
id: '1', name: 'Administrador',
email: 'admin@mail.com',
username: 'admin',
password: 'xxx',
posts: [1, 2, 3]
}]

@broerse
Copy link
Collaborator

broerse commented Jun 4, 2018

When you save the post do you update the author like this? https://github.com/pouchdb-community/relational-pouch#many-to-one-relationships

You can also use queryInverse in your schema an include 'pouchdb-find' in your project. You don't have to save the hasMany side in this case.

@fransyozef
Copy link

You do need to supply the author id in the post. Otherwise you cannot ever find the post back to the author.

What I normally do is

  1. get the author record
  2. get the id
  3. add the new post with the author id

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

3 participants