Requesting for `.parent()` and `.ownerDocument()` in a document class
See original GitHub issueWhich 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:
- Created 3 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 useparent()
, or any of the other methods described inEmbedded
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.
closing because stale & not a typegoose issue