question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Requesting for `.parent()` and `.ownerDocument()` in a document class

See original GitHub issue

Which feature

Mainly requesting for the .ownerDocument() and .parent() features.

Code Examples

Most of the time used in pre-validations:

SomeSchema.pre('validate', function (next) {
  const isParentSomething = this.parent().something
  if (!isParentSomething) {
    return next(new Error('Subdoc cannot be inserted into parent without something'))
  }
}

Currently, in the Typegoose equivalent,

@pre<SomeClass>('validate', function (next) {
  // Property 'parent' does not exist on type 'DocumentType<SomeClass>'.
  const isParentSomething = this.parent().something
  ...
})

Basically requesting for this in pre/post/ other mongoose hooks to also include the parent and ownerDocument property.

Additional Notes

I’m quite new to Typegoose, so if there is another way to do what I asked without using .parent or .ownerDocument, I’d be very happy too!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
trapparcommented, Jun 30, 2020

This is also currently an issue with subdocuments. I haven’t been able to find any good way to type them. The problem is that even if you use Embedded, it won’t really help since it’s not a generic. This means that when you use parent(), or any of the other methods described in Embedded it won’t return a document that’s aware of what type the parent document is.

My temporary solution is to just create a custom type which is a combination of DocumentType and custom types for the methods I want to use. Pretty poor solution… but at least it works.

0reactions
hasezoeycommented, Aug 19, 2020

closing because stale & not a typegoose issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

doc.parent() and doc.ownerDocument() consistency #10884
parent() from a root document it returns undefined. doc.ownerDocument() isn't in the API documentation. IMHO doc.parent() and doc.ownerDocument ...
Read more >
org.jsoup.nodes.Element.ownerDocument java code examples
Finds elements, including and recursively under this element, with the specified tag name. children. Get this element's child elements. This is effectively a ......
Read more >
HTML DOM ownerDocument Property - W3Schools
The ownerDocument property returns the owner document of a node, as a Document object. In HTML, the HTML document itself is always the...
Read more >
Node.ownerDocument - Web APIs | MDN
The read-only ownerDocument property of the Node interface returns the top-level document object of the node.
Read more >
ParentNode (Xerces2 Implementation) - Apache Xerces
ParentNode inherits from ChildNode and adds the capability of having child nodes. Not every node in the DOM can have children, so only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found