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

Saving a doc with inner objects behavior #41

Open
ramonsan opened this issue Sep 24, 2015 · 2 comments
Open

Saving a doc with inner objects behavior #41

ramonsan opened this issue Sep 24, 2015 · 2 comments

Comments

@ramonsan
Copy link

Suppose we have a javascript object with a inner object that we want to save as a doc in pouchdb . In my case it has more lines and a couple of relationships, but for simplicity :

{
  id : "doc1",
  name : "Document 1",
  props : {
    id : 1,
    prop1 :  "hello",
    prop2 : "world"
  }
}

In normal pouch, we can put this to save a doc like:

Image of normal pouchdb

But, if when we try to save with db.rel.save, it only stores the id of object, skipping all other content:
Image of relational-pouchdb

If before call db.rel.save, I do doc.props = [doc.props]; it will be stored as an array with the entire object. It has a big side effect doing this when we retrive in client, console.log($scope.doc) prints all doc correclty (including prop as an array with one object), but doing console.log($scope.doc.props) throws undefined.

So, what's happening when saving an object inside doc? It is the normal behavior?

@ramonsan
Copy link
Author

I found the guilty of this behavior. If the inner object has an id prop, trigger that. So this work:

{
  id : "doc1",
  name : "Document 1",
  props : {
    prop1 :  "hello",
    prop2 : "world"
  }
}

So, when I add a object to a doc, I save that prop in a standalone prop and then delete it from object. The result is:
Image of result without id

@nolanlawson
Copy link
Member

This sounds like a bug in relational-pouch. So you're saying if there's an id prop anywhere, then it will remove the object? Definitely a bug; that should only happen if you define a schema.

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